Your question is not specific enough. You didn't describe the rules for the
format of the strings; you gave 2 possible examples. For example, could the
string in question look like this:
4 5 5 5 6 Gothenburg
or 45 556 Whatever
or 45556 Something with spaces
?
The best answer depends on the formatting rules for the source string. For
example, you could cover all possible bases by:
string source = "4 55 56 Gothenburg";
int i, len, pos = 0;
StringBuilder sb = new StringBuilder();
len = source.Length;
sb.Capacity = len;
for (i = 0; i < len; i++)
{
if (Char.IsDigit(source[i])
{
sb.Append(source[i]);
if (++pos == 3) sb.Append(' ');
else if (pos == 5)
{
sb.Append(' ');
do (i++) while (i < len && Char.IsSeparator(source[i]);
while (i < len) sb.Append(source[i]);
}
}
}
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
"Visual Systems AB (Martin Arvidsson)" <ma**************@vsab.net> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!
I have a string, it could look like this
455 56 Gothenburg or 45556 Gothenburg
What i want to do is to separate the numbers from the text into two
different strings
and the numbers i would like to formate like ### ##.
My brain is just not giving me any direction on how to solve this :D
//Martin, Sweden