breaking a string to substrings
-
i am having a string ,say"14p"....I want to take only the value 14 so that i could convert that to integer..how can i achieve this?
-
i am having a string ,say"14p"....I want to take only the value 14 so that i could convert that to integer..how can i achieve this?
n i want to split that string on occurence of any alphabets
-
n i want to split that string on occurence of any alphabets
hi, I did this using regular expressions. I wrote a method to split a string by alphabetic characters. 14p gives array of one item 14 14eur gives an array of one item 14 14eur14pp15p gives an array of 3 items 14, 14, and 15 http://pastebin.com/f55499ed[^]
modified on Wednesday, December 30, 2009 2:56 AM
-
i am having a string ,say"14p"....I want to take only the value 14 so that i could convert that to integer..how can i achieve this?
Assume that your input string like: Input: a1f2g3r46mj5kde6 Output:123456 I think at first you split it in to an array and pass each array item to a function for numeric validation. That.s It...:)
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
-
hi, I did this using regular expressions. I wrote a method to split a string by alphabetic characters. 14p gives array of one item 14 14eur gives an array of one item 14 14eur14pp15p gives an array of 3 items 14, 14, and 15 http://pastebin.com/f55499ed[^]
modified on Wednesday, December 30, 2009 2:56 AM
how about this -
public String[] Split(String alpha)
{
String str = alpha;
List<String> returnVal = new List<String>();Regex regexp = new Regex("\[0-9\]+"); MatchCollection matchColection = regexp.Matches(str); for (int i = 0; i < matchColection.Count; i++) { returnVal.Add(matchColection\[i\].Value); } return returnVal.ToArray(); }
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder