Exracting char from string

  • Thread starter Thread starter Wndr
  • Start date Start date
W

Wndr

Hi guys;
I am new to C#.
I have a string for example:
1,2,3,6,7,8 and I need to parse this string into something like that: 1-3,
6-8
Does any body have some sample on how it could be done in C#.
Thanks in advance
 
string s = "12345678";
foreach (char c in s.ToCharArray())
Console.WriteLine(c.ToString());
Hope I understood your question....
 
Hi guys;
I am new to C#.
I have a string for example:
1,2,3,6,7,8 and I need to parse this string into something like that: 1-3,
6-8
Does any body have some sample on how it could be done in C#.
Thanks in advance

Something like this maybe?

private string parse()
{
string test = "1,2,3,5,6,7";
char [] testArray = test.ToCharArray();

//string that holds final result
string final = "";

foreach(char c in testArray)
{
//put your logic here to compose the new string in
'final'
}
return final;
}
 
I work with VB, and I have this function is VB, but it's too long to redo
everything in C#, so I just was wondering if there is an easier/shorter way
to do it in C#.
I am working with C# second day, so sorry if my question it too obvious.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top