Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get a string manipulation?

How I'll assign the string x = "490.00 001.09 987.1 876.99" into

x1 = "490.00"
x2 = "001.09"
x3 = "987.1"
x4 = "876.99"

Please advice me.. tnx!

like image 603
ghie Avatar asked Jun 26 '26 06:06

ghie


2 Answers

You can use the String.Split Method which splits the string by a separator character into multiple parts. The default separator is any whitespace character:

 string x = "490.00 001.09 987.1 876.99";

 string[] parts = x.Split();

 string x1 = parts[0];
 string x2 = parts[1];
 string x3 = parts[2];
 string x4 = parts[3];
like image 180
dtb Avatar answered Jun 28 '26 19:06

dtb


In your very specific case, this will work:

var x = "490.00 001.09 987.1 876.99";
var parts = x.Split(new char[] { ' ' });

var x1 = parts[0];
var x2 = parts[1];
var x3 = parts[2];
var x4 = parts[3];
like image 45
Yuck Avatar answered Jun 28 '26 18:06

Yuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!