i have a string like 123Prefix1pics.zip
i want to split it into 123 Prefix1 pics.zip and store them in different variables i m trying to do it in c#,.net jst litle bit confused on how to use split method
i have a string like 123Prefix1pics.zip
i want to split it into 123 Prefix1 pics.zip and store them in different variables i m trying to do it in c#,.net jst litle bit confused on how to use split method
Look like you want to split by fixed size.
So use yourString.Substring(0, 3);
splitArray = Regex.Split(subjectString, @"(?<=\p{N})(?=\p{L})");
will work in C# to split in positions between a number (\p{N}
) and a letter (\p{L}
).
If you also want to split between a letter and a number, use
splitArray = Regex.Split(subjectString, @"(?<=\p{L})(?=\p{N})|(?<=\p{N})(?=\p{L})");
however, that splits your example too much.
You can start with:
string filename = "123Prefix1pics.zip"
string part1 = filename.Substring(0, 3);
string part2 = filename.Substring(3, 7);
string part3 = filename.Substring(10, 4);
You can also note String.Split() needs a separator argument, like an ;
or ,
. As you don't have any separator, you can try two approaches:
Substring()
to break your stringsI recommend you to stick with first option.
You only want to split that one string? Too easy!
string filename = "123Prefix1pics.zip"
string part1 = "123"
string part2 = "Prefix1"
string part3 = "pics.zip"
Ok this is a joke, but it gives the right answer. Unless you generalise your splitting rule, or provide further examples, we can only guess.
You may be asking to make a string break after a numeral, but again I'm only guessing.