This question already has answers here:
Easiest way to parse a comma delimited string to some kind of object I can loop through to access the individual values?
(7 answers)
Closed 8 years ago.
What would be the most elegant way to extract values from a string of comma-separated numbers?
It should account for whitespaces too. Example:
Input string: "22,10,8,13"
Input string: "22, 10, 8, 13"
Input string: "22, 10 ,8 ,13,"
Given all three inputs, the method should recognise the values.
Example output for all three inputs: "String contains: 22 10 8 13"
Possible duplicate: Easiest way to parse a comma delimited string to some kind of object I can loop through to access the individual values?
string input = "22,10 ,8 , 13";
var output = input.Split(',').Select(i=>i.Trim());
Related
This question already has answers here:
How can I convert String to Int?
(31 answers)
String.Format an integer to use a thousands separator with decimal value in danish culture
(5 answers)
How would I separate thousands with space in C#
(6 answers)
Closed 2 years ago.
I'm receiving a string value (for example "331000110.00") and I want to convert it so it has thousands separators (I want to have something like this: 331 000 110.00). Important thing is that I want this field to stay as a string. Anyone can help me with this?
This question already has answers here:
Check if a string contains one of 10 characters
(6 answers)
Closed 2 years ago.
I have this array:
char[] signOfDecimal = {',', '.'};
and I'm trying to find the location of one of these 2 characters in my string:
locationOfDotInRate = myString.IndexOf(signOfDecimal[0], signOfDecimal[1]);
Basically I'm trying to check where one of these characters might occur in my string, but its not working. The reason I'm doing it this way is because my string sometimes contain '.' or ','.
You can use IndexOfAny method
locationOfDotInRate = myString.IndexOfAny(signOfDecimal);
This question already has answers here:
C# string splitting
(4 answers)
Closed 7 years ago.
I need to be able to extract the three strings separated by a dashes "-" from an input string.
For example:
Mystring="54-0-9";
the values separated by "-" are with unknown length because they should be an input for the user.
The user should enter each value in a textField than my code concatenate the 3 values and put it as shown . Later i want to get the three values separated again each one in a new text field. How can i do that in c# !?
Using string split.
// Select on "-".
string[] split = _string.Split(new Char[] { '-' });
split[0], split[1], split[2] will have the values you want.
Mystring="54-0-9";
Mystring.Split('-');
this will give you a array of 3 now.
This question already has answers here:
Parse strings to double with comma and point
(14 answers)
Closed 8 years ago.
I am trying to read a number from the console, but if it is input via comma (ex. 2,56), it cannot be parsed successfully. It can be parsed only if it is input like this: 2.56
How can I change that?
Here is a sample code:
if (double.TryParse(stringElements[i], out doubleNum))
{
averageTime.Add(doubleNum);
}
replace the comma by '.' like this :
save your number in variable X , then
if (double.TryParse((X).Replace(",", "."), out tmp))
{
}
replace with "."
Convert.ToDouble("2,56".Replace(",", "."));
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Split String into smaller Strings by length variable
I have seen solutions that split strings by a certain character but I wanted to seperate a string every certain amount of characters. Does anyone know how to do this?
its been asked
Split String into smaller Strings by length variable