Finding a specific character in a string

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2008
Posts: 56
Reputation: love_dude1984 is an unknown quantity at this point 
Solved Threads: 2
love_dude1984 love_dude1984 is offline Offline
Junior Poster in Training

Finding a specific character in a string

 
0
  #1
28 Days Ago
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.

  1.  
  2. str = TextBox1.Text.Trim();
  3. temp = str;
  4. for (int j = 0; j < str.Length; j++)
  5. {
  6. if (str.Contains(" "))
  7. {
  8.  
  9. i = str.IndexOf(" ");
  10. str=str.Substring(i, str.Length - (i+1));
  11. Response.Write(" This is index "+i);
  12. Response.Write(" This is next string : "+str);
  13. }
  14.  
  15. }

hope to get a help soon..

thanks..
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 176
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 13
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster
 
0
  #2
28 Days Ago
Originally Posted by love_dude1984 View Post
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.

  1.  
  2. str = TextBox1.Text.Trim();
  3. temp = str;
  4. for (int j = 0; j < str.Length; j++)
  5. {
  6. if (str.Contains(" "))
  7. {
  8.  
  9. i = str.IndexOf(" ");
  10. str=str.Substring(i, str.Length - (i+1));
  11. Response.Write(" This is index "+i);
  12. Response.Write(" This is next string : "+str);
  13. }
  14.  
  15. }

hope to get a help soon..

thanks..
Like this ?
  1. Dim NoList As String()
  2. Dim I As Byte
  3. NoList = Split(TextBox1.Text.Trim, ",")
  4. For I = 0 To NoList .Length - 1
  5. Response.Write(" This is index " & CStr(i))
  6. Response.Write(" This is next string : " & NoList(i))
  7. Next I
Last edited by Kusno; 28 Days Ago at 5:26 am. Reason: wrong
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 432
Reputation: Ramesh S will become famous soon enough Ramesh S will become famous soon enough 
Solved Threads: 82
Ramesh S Ramesh S is offline Offline
Posting Pro in Training
 
0
  #3
28 Days Ago
You can split a string into array of sub strings based on delimiter character such as space, comma.

  1. string str = TextBox1.Text.Trim();
  2. string[] temp = str.Split(' ');
  3. for (int j = 0; j < temp.Length; j++)
  4. {
  5. Response.Write(" This is index " + j.ToString());
  6. Response.Write(" This is the string : " + temp[j]);
  7. }
  8.  
  9. }
Last edited by Ramesh S; 28 Days Ago at 5:41 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training
 
0
  #4
28 Days Ago
Try this
  1. string str = TextBox1.Text.Trim();
  2. for (int i = 0; i < str.Length; i++) {
  3. if (!str[i].Equals(Convert.ToChar(32))) {
  4. newList.Add(str[i]);
  5. }
  6.  
  7. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 56
Reputation: love_dude1984 is an unknown quantity at this point 
Solved Threads: 2
love_dude1984 love_dude1984 is offline Offline
Junior Poster in Training

Thank you..

 
0
  #5
28 Days Ago
Thank you frends...

i have got the solution.

Thanks agen..
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training
 
0
  #6
28 Days Ago
Originally Posted by love_dude1984 View Post
Thank you frends...

i have got the solution.

Thanks agen..
Please close the thread by marking it as solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC