Reputation:
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
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
Reputation: 2161
Its almost the same:
// splitting by space
var d = string.Join (" ", c.Split (' '));
Upvotes: 0
Reputation: 1674
d = string.Join(null, c.Split(null)); //null is your separator where you can change it to " "
Upvotes: 0