0

hello frndz..
i really need some urgent help on a simple problem.

im storing a string in a database, say its "1 2 3",these are actually the id's of something. in order to get the name from the ID, i need to seperate the id's from the string, that is 1,2,3. in a array may b. so i just want to know how i can achieve the same thing.
i tried this code, but its not working properly.

str = TextBox1.Text.Trim();
        temp = str;
        for (int j = 0; j < str.Length; j++)
        {
            if (str.Contains(" "))
            {
                
                i = str.IndexOf(" ");
                str=str.Substring(i, str.Length - (i+1));
                Response.Write("  This is index "+i);
                Response.Write("  This is next string : "+str);
            }
            
        }

hope to get a help soon..

thanks..

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by carobee
0

hello frndz..
i really need some urgent help on a simple problem.

im storing a string in a database, say its "1 2 3",these are actually the id's of something. in order to get the name from the ID, i need to seperate the id's from the string, that is 1,2,3. in a array may b. so i just want to know how i can achieve the same thing.
i tried this code, but its not working properly.

str = TextBox1.Text.Trim();
        temp = str;
        for (int j = 0; j < str.Length; j++)
        {
            if (str.Contains(" "))
            {
                
                i = str.IndexOf(" ");
                str=str.Substring(i, str.Length - (i+1));
                Response.Write("  This is index "+i);
                Response.Write("  This is next string : "+str);
            }
            
        }

hope to get a help soon..

thanks..

Like this ?

Dim NoList As String()
 Dim I As Byte       
 NoList = Split(TextBox1.Text.Trim, ",")
 For I = 0 To NoList .Length - 1
            Response.Write("  This is index " & CStr(i))
            Response.Write("  This is next string : " & NoList(i))
  Next I

Edited by Kusno: wrong

0

You can split a string into array of sub strings based on delimiter character such as space, comma.

string str = TextBox1.Text.Trim();
        string[] temp = str.Split(' '); 
        for (int j = 0; j < temp.Length; j++)
        {
                Response.Write("  This is index " + j.ToString());
                Response.Write("  This is the string : " + temp[j]);
            }

        }

Edited by Ramesh S: n/a

0

Try this

string str = TextBox1.Text.Trim();
        for (int i = 0; i < str.Length; i++) {
            if (!str[i].Equals(Convert.ToChar(32))) {
                newList.Add(str[i]);
            }
            
        }
0

Thank you frends...

i have got the solution.

Thanks agen..

Please close the thread by marking it as solved

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.