user6139904
user6139904

Reputation:

How to convert this Python code to c#?

I'm fairly decent at python and just starting to learn C#.

How would i write this peice of python code in c#?

 d =" ".join(c.split())

I'm a c# beginner so nothing too technical please.

Upvotes: 0

Views: 110

Answers (3)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186668

As far as I can see

 c.split()

is splitting string c by default - (space) - delimiter; C# equivalent is

 c.Split(' ');

Pythonic

 " ".join

is collection joining with " " being the delimiter; C# equivalent is

 string.Join(" ", collection);

Binding all together:

 d = string.Join(" ", c.Split(' '));

Upvotes: 2

Markiian Benovskyi
Markiian Benovskyi

Reputation: 2161

Its almost the same:

// splitting by space
var d = string.Join (" ", c.Split (' '));

Upvotes: 0

jace
jace

Reputation: 1674

d = string.Join(null, c.Split(null)); //null is your separator where you can change it to " "

Upvotes: 0

Related Questions