I am really confused on this one. I have 5 elements in a string array. - string[] strings = { "Widget 15.50", "Thingy 50.99", "Ratchet25.00", "Clanger115.49", "Fracker75.25" };
I have to separate the text from the numbers into two new arrays. One string containing {"Widget ", "Thingy", "Ratchet", "Clanger", "Fracker"} and the second a double array containing {15.50, 50.99, 25.00, 115.49, 75.25}
I don't know how to do this with an array. Can someone help?
Something like this might work -
string[] strings = { "Widget 15.50", "Thingy 50.99", "Ratchet25.00", "Clanger115.49", "Fracker75.25" };
-
double[] values = new double[4];
-
int n = 0;
-
foreach(string s in strings)
-
{
-
string[] foo = s.split(' ');
-
values[n++] = Convert.ToDouble(foo[1])
-
}
-
Though a far better way would be to have this -
List<string> things = new List<string>();
-
List<double> values = new List<double>();
-
string[] strings = { "Widget 15.50", "Thingy 50.99", "Ratchet25.00", "Clanger115.49", "Fracker75.25" };
-
foreach(string s in strings)
-
{
-
string[] foo = s.split(' ');
-
things.Add(foo[0]);
-
values.Add(Convert.ToDouble(foo[1]);
-
}
-
Far less hassle than using arrays....
2 2189
Something like this might work -
string[] strings = { "Widget 15.50", "Thingy 50.99", "Ratchet25.00", "Clanger115.49", "Fracker75.25" };
-
double[] values = new double[4];
-
int n = 0;
-
foreach(string s in strings)
-
{
-
string[] foo = s.split(' ');
-
values[n++] = Convert.ToDouble(foo[1])
-
}
-
Though a far better way would be to have this -
List<string> things = new List<string>();
-
List<double> values = new List<double>();
-
string[] strings = { "Widget 15.50", "Thingy 50.99", "Ratchet25.00", "Clanger115.49", "Fracker75.25" };
-
foreach(string s in strings)
-
{
-
string[] foo = s.split(' ');
-
things.Add(foo[0]);
-
values.Add(Convert.ToDouble(foo[1]);
-
}
-
Far less hassle than using arrays....
Awesome!! Thank you so much!!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Keiron Waites |
last post by:
I get the following error:
Notice: Array to string conversion in C:\Documents and
Settings\ShepMode\Desktop\Websites\ShareMonkey.net\Web\join.php on line 11
in this code:
$input =...
|
by: john |
last post by:
Relatively new to C coding, so any help would greatly be appreciated.
I'm having problems try to return my string array from my parsing
function. When I do a printf I am getting the correct value...
|
by: Garfield |
last post by:
Hello
I have a function that returns a string array. The string has a name and an ID number, they are separated by a comma.
I cannot for the life of me by using the string methods get to...
|
by: NuBBeR |
last post by:
I have a string that i have split into an array and what i would like to do
is go through each of the items in the array and parse 3 substrings for that
string:
string str = (temp.substr(start,...
|
by: zlf |
last post by:
Hi,
This there any existing alorgithm in .NET that can extract the common
element in two string arrays to another string array;
usage:
string a = { "1","2","3" };
string b = { "1" };
string...
|
by: DumberThanSnot |
last post by:
is there a faster way to copy an ArrayList of strings to a string other than
a tight loop.
In it's most simple terms, I'm currently using something like this...
----------------------------
...
|
by: Paulers |
last post by:
Hello all,
I have a string array with duplicate elements. I need to create a new
string array containing only the unique elements. Is there an easy way
to do this? I have tried looping through...
|
by: dotnetnoob |
last post by:
i have a arraylist that store String() array
the string array hold value 1 2 4
i want to access the string array that is inside the arraylist one arraylist
item at the time
i search up and...
|
by: LinLMa |
last post by:
Hello everyone,
I find strange result in the following program.
1. For string array, dereferencing it will result in the string
itself, but for int array, dereferencing it will result in the...
|
by: David Lazos |
last post by:
Hi All,
I use Contains method of String object to determine if a string variable
has another string, like that.
***************************
ipAddress.Contains("127.0.0")...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |