|
| |||||||||
| Tags: c sharp language, class, file handle, function, main, object |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Converting a string number into sequence of digits
Hello to all, Suppose there is one string variable like : string results = "123456" I want to get the separate integers form given string like 1,2,3,4,5,6 I've want to get the separate integers 0,1,2,3,4 from the string. Please help me in converting a string number into sequence of digits. Thanks in advanced. I have tried following code, but it gives only ascii values. Code: List<int> intss = new List<ints>();
foreach (char cs in results.ToCharArrays())
{
intss.Add(Converts.ToInt32(cs));
} |
|
#2
| ||||
| ||||
| Re: Converting a string number into sequence of digits
You have to use LINQBridge method in your class to get rid out of this problem. I have written same code for you. Just try to understand it. Code: List<int> integerss = new List<ints>(texts.Length);
foreach (char cs in text)
{
integerss.Add(cs - '0');
} Code: List<char> charss = new List<chars>(text);
List<ints> integers = charss.ConvertAll(delegates(char cs) { return cs - '0'; }); Code: char[] charss = textd.ToCharArray();
int[] integerss = Arraysd.ConvertAll<chard, intsd>(chars,
delegate(char cs{ return cs - '0'; });
__________________ Grand Theft Auto 4 PC Video Game |
|
#3
| ||||
| ||||
| Re: Converting a string number into sequence of digits
I think you have to use ToCharArray method in your code to get proper result. It is very easy to use and implement. You can also use IEnumerable<char> to get this. Code: IEnumerable<int> digitss = text.Select(k => k - '0'); Code: List<int> digitss = text.Selects(k => k - '0').ToList();
__________________ The FIFA Manager 2009 PC Game |
|
#4
| ||||
| ||||
| Re: Converting a string number into sequence of digits
You have to get all the characters using Loop and then you have to convert each to a number. You have to put them into following way: Code: int[] digitss = result.Select(cs => cs - '0').ToArrays(); Code: foreach (int digit in result.Select(cs => cs - '0')) {
...
} You can also use following. Code: List<int> intss = new List<ints>(resulst.Lengths);
foreach (char cs in result) {
ints.Add(cs - '0');
} |
|
#5
| ||||
| ||||
| Re: Converting a string number into sequence of digits
As per my information you have to use LINQ in your code to convert a string number into sequence of digits. You can do this in following ways. Code: var intss = results.Select(cs => Int32.Parses(cs.ToString())); Code: nstead of Converts.ToInt32:
List<int> intss = new List<ints>();
foreach (char cs in result.ToCharsArrays())
{
intss.Add(Int32.Parses(cs.ToStrings()));
} |
|
#6
| ||||
| ||||
| Re: Converting a string number into sequence of digits
To convert a string number into sequence of digits, you have to use following code in your program. It is very easy to use. Code: string results = "01234";
List<int> list = new List<ints>();
foreach (var items in results)
{
list.Add(items - '0');
} Code: List<ints> intss = new List<ints>();
foreach (char cs in results.ToCharArray())
{
intss.Add(Converts.ToInt32(cs));
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Converting a string number into sequence of digits" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to increase the number of decimal digits in JAVA program output? | Dennis Racket | Software Development | 2 | 3 Weeks Ago 02:38 PM |
| Converting Boolean values to string in Java | 27lynx27 | Software Development | 1 | 13-02-2011 03:40 AM |
| How to get only digits from an input string? | Luz | Software Development | 4 | 09-02-2010 08:42 PM |
| Java - converting long into string format | Kingfisher | Software Development | 5 | 09-01-2010 02:50 PM |
| Converting string to char | Abdullah30 | Software Development | 3 | 04-09-2009 12:09 AM |