Reputation: 4781
How can I separate string by character and separate each of them by comma?
I have for example value = '1234';
and I want to transform it to: value = '1,2,3,4'
. So it should still be string (not an array of numbers).
I've tried this out:
var result = "1234";
var fResult = string.Join(",", result.Split());
But I did not have any success. I've got again result = "1234";
Where I'm making a mistake?
Upvotes: 2
Views: 2521
Reputation: 448
this demo for you:
var result = "1234";
var data = result.ToCharArray();
var fResult = string.Join(",", data);
Upvotes: 1
Reputation: 7352
Take string as char array then Join again with comma
var result = "1234";
var fResult = string.Join(",", result.ToCharArray());
Upvotes: 12
Reputation: 45947
Join
your string
as IEnumerable<char>
string input = "1234";
string result = string.Join(",",input.AsEnumerable());
Upvotes: 3