Splitting number and string using linq
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?
No comments:
Post a Comment