I need to read only specific portions of a complete string. The string would be in the form of:
"1 Some Currency Name = 0.4232 Other Currency Name"
So, the quickest method I could come up with was to split the string at the equal (=) operator thus adding two values to the array, like so:
string rawInput = "1 Some Currency Name = 0.4232 Other Currency Name";
string[] rawSplit = rawInput.Split('=');
string firstRate = rawSplit[0].ToString();
string secondRate = rawSplit[1].ToString();
I now need to get only the first part of the secondRate string ("0.4232"). So I would split that string again (bad coding):
string[] lastSplit = secondRate.Split(); //Split at whitespace characters
string firstValue = lastSplit[0].ToString(); //Should return "0.4232" but instead returns ""
When I run the application to test this function, it returns an empty string instead of the value "0.4232". Why is this happening? What am I missing here?
Complete Method:
private void btnTest_Click(object sender, EventArgs e)
{
string rawInput = "1 Some Currency Name = 0.4232 Other Currency Name";
string[] rawSplit = rawInput.Split('=');
string baseRate = rawSplit[0].ToString(); //1 Some Currency Name
string conversionRate = rawSplit[1].ToString(); //0.4232 Other Currency Name
rawSplit = GetSplit(conversionRate);
XtraMessageBox.Show(rawSplit[0].ToString()); //Returns blank string here???
}
private string[] GetSplit(string inputString)
{
return inputString.Split();
}
Any ideas or suggestions welcome and will be greatly appreciated!
=then the string will be ` 0.4232...` which means the first entry is empty when splitting by whitespace.ToString()on values which are already strings?