How To Separate Number ?
-
If i have vriable string i; // i = 34245 (Whatever use put a number) If i want to separate the "34245"(by one digit)So what method should i use. i want to make a program where usere put any number and result come like 12345 one two three four five. Is thay anyone can help me with that ? -Thanks
Peter
-
If i have vriable string i; // i = 34245 (Whatever use put a number) If i want to separate the "34245"(by one digit)So what method should i use. i want to make a program where usere put any number and result come like 12345 one two three four five. Is thay anyone can help me with that ? -Thanks
Peter
A string is an array of chars. foreach(char c in "12345") will iterate over the numbers. If you have non numbers in your string, Char.IsDigit will tell you if it's a number.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
A string is an array of chars. foreach(char c in "12345") will iterate over the numbers. If you have non numbers in your string, Char.IsDigit will tell you if it's a number.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
in ouput only comes the value of last digit if out put is 12345 five it's loop through one two three four five but pirnt only five ? no one two three four is on screen only five... can you tell me how should i get the whole value ? 12345 one two three four five -Thanks
Peter
-
in ouput only comes the value of last digit if out put is 12345 five it's loop through one two three four five but pirnt only five ? no one two three four is on screen only five... can you tell me how should i get the whole value ? 12345 one two three four five -Thanks
Peter
I have no idea where your code is broken, you've not posted it. foreach(char c in "12345") { switch(c) { case '1': // print 'one' // etc } } will most certainly work.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I have no idea where your code is broken, you've not posted it. foreach(char c in "12345") { switch(c) { case '1': // print 'one' // etc } } will most certainly work.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Ah, but a
Dictionary<char,string>
would be so much more flexible and the teacher will be most impressed. ;P -
Ah, but a
Dictionary<char,string>
would be so much more flexible and the teacher will be most impressed. ;PYeah, until the teacher asked him to explain the code....
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Yeah, until the teacher asked him to explain the code....
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Oh, in that case maybe an
enum
. -
Oh, in that case maybe an
enum
.How about just an array of strings and int.TryParse to get the index ?
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
How about just an array of strings and int.TryParse to get the index ?
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Ah, but a
Dictionary<char,string>
would be so much more flexible and the teacher will be most impressed. ;PI seriously doubt it's homework help he's asking.
Cheers, Vikram.
Zeppelin's law: In any Soapbox discussion involving Stan Shannon, the probability of the term "leftist" or "Marxist" appearing approaches 1 monotonically. Harris' addendum: I think you meant "monotonously". Martin's second addendum: Jeffersonian... I think that should at least get a mention.
-
I seriously doubt it's homework help he's asking.
Cheers, Vikram.
Zeppelin's law: In any Soapbox discussion involving Stan Shannon, the probability of the term "leftist" or "Marxist" appearing approaches 1 monotonically. Harris' addendum: I think you meant "monotonously". Martin's second addendum: Jeffersonian... I think that should at least get a mention.
Oh, no, most assuredly not. :-D