I have a semicolon-separated list of values, for example:
strins s = "param1=true;param2=4;param3=2.0f;param4=sometext;";
I need a functions:
public bool ExtractBool(string parameterName, string @params);
public int ExtractInt(string parameterName, string @params);
public float ExtractFloat(string parameterName, string @params);
public string ExtractString(string parameterName, string @params);
Is there a special functions in .net that can help me with semicolon-separated list ?
PS: parameter names are equal within a list.
As a starting point, what you need is the String.Split() method - it will split your string into a string array.
You'll find loads of examples of this all over the web.
For string better you can use Split(';');
You can try this for split comma
string s ="param1=true;param2=4;param3=2.0f;param4=sometext;";
string[] sArray = s.Split(';')
Here is a better way to do this and avoid having a whole bunch of empty array elements:
string lsToString = "Your String Here";
string[] laChars = { "," };
string[] laTo = lsToString.Split(laChars, StringSplitOptions.RemoveEmptyEntries);
Makes it much easier to work with after you split the string because you don't have to worry about empty elements.
Pete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With