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..

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

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]);
            }

        }

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]);
            }
            
        }

Thank you frends...

i have got the solution.

Thanks agen..

Thank you frends...

i have got the solution.

Thanks agen..

Please close the thread by marking it as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.