tags:

views:

88

answers:

4

how can i read string values

QuoteNo:32586/CustomerNo:ABCDEF/TotalAmount:32/Processed:No

i want to read the values of the strings in any order

+3  A: 
  1. split the string by / into array
  2. loop through the array and split each entry by : (basically creating key pair value), shove that into a dictionary, the key will be the array at index 0 and value at index 1
  3. Once you have your dictionary, you can just do something like: myData["QuoteNo"] or myData["CustomerNo"]
Jimmy Chandra
+1 was just writing the same reply....
Tim Jarvis
+3  A: 

Not sure what you're looking to do, but from your given string it may be the following

string input = "QuoteNo:32586/CustomerNo:ABCDEF/TotalAmount:32/Processed:No";

var query = from pair in input.Split('/')
            let items = pair.Split(':')
            select new
            {
                Part = items[0],
                Value = items[1]
            };

 // turn into list and access by index 
var list = query.ToList();

// or turn into dictionary and access by key
Dictionary<string, string> dictionary 
    = query.ToDictionary(item => item.Part, item => item.Value);
Anthony Pegram
A: 
string str = "QuoteNo:32586/CustomerNo:ABCDEF/TotalAmount:32/Processed:No";
string split = str.Split('/');
foreach(string s in split)
{
   int index = s.IndexOf(':');
   if (index <= 0 || index + 1 >= str.Length) throw new Exception();
   string name = s.SubString(0,index);
   string value = s.SubString(index+1);
}
Itay