I have a string which its first part is a string and last one is a number, like this:
ahde7394
so what I would like to obtain is:
ahde
7394
I have thought to first extract the string and then from the last position of the character obtain the number until the end of the string so I think using indexers can be done somehow:
var stringQuery = NameComp.Select((str,index) => new {myStr=str, position=index})
.Where(c => !Char.IsDigit(c.myStr)).Select((ch,pos) => new { newStr=ch, pos=pos} );
then I could do:
1) To obtain the string: stringQuery.newStr
2) To obtain the number: stringQuery.Skip(stringQuery.pos).Select(d => d);
but it is not working, after obtaining stringQuery I cannot access to its items as it is an anonymous type....
Any ideas?
Solution using LINQ, guessing that str="ahde7394":
string letters = new string(str.TakeWhile(c => Char.IsLetter(c)).ToArray());
and for number:
string number = new string(str.Skip(letters.Length).TakeWhile(c => Char.IsDigit(c)).ToArray());
or better guessing last part is a number:
string number = str.Substring(name.Length);