Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have a string list which like
C#
String xmlTest="MOBILE DEVICE~!20^!PRINTERE~!25^!MOBILE SCANNER~!23^!";
            String rec[]=xmlTest.split("^!");

and try to enter into a list view

C#
for (int i = 0; i < rec.length; i++) {
                String fld[]=rec[i].split("~!");
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
                        map.put(KEY_TITLE,fld[0]);
    			map.put(qty, fld[1]);
                        List.add(map);
}




But it is adding only first line like
MOBILE DEVICE 20
Second line should come
PRINTER 25
But it is not coming second line, third line etc please help


Thanks to All
Posted
Comments
_Asif_ 8-Sep-14 6:35am    
Well the loop seems correct, problem is somewhere else. Did you debug?
Benjano 8-Sep-14 6:41am    
You've marked this as a C# question, but this looks like Java?
Herman<T>.Instance 8-Sep-14 7:27am    
true! You cannt split directly on 2 chars in c#, You do that another way. This question is doubtful therefore. A RegEx could be used for that
santoshkrpathak@gmail.com 11-Sep-14 6:06am    
In C# we can spilt by String,Please see solution 2.
Have you debugged?

use this code.

C#
string xmlTest="MOBILE DEVICE~!20^!PRINTERE~!25^!MOBILE SCANNER~!23^!";
        string[] rec=xmlTest.Split(new string[] {"^!"},StringSplitOptions.None);



C#
for (int i = 0; i < rec.Length; i++) {
            string[] fld = rec[i].Split(new string[] { "~!" }, StringSplitOptions.None);}
 
Share this answer
 
Below solution is working ,let me know in case of any question

C#
String xmlTest = "MOBILE DEVICE~!20^!PRINTERE~!25^!MOBILE SCANNER~!23^!";
            string[] splitArrayString = { @"^!" };
            string[] splitArrayString1 = { @"~!" };
            string[] SplitedValues = xmlTest.Split(splitArrayString, StringSplitOptions.RemoveEmptyEntries);
            var queryStr = from val in SplitedValues
                           let splitted = val.Split(splitArrayString1, StringSplitOptions.RemoveEmptyEntries)
                           select new { KEY_TITLE = splitted[0], qty = splitted[1] };






           ListView1.DataSource= queryStr.ToList();
           ListView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900