943,945 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 2457
  • ASP.NET RSS
Oct 29th, 2009
0

Finding a specific character in a string

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

ASP.NET Syntax (Toggle Plain Text)
  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..
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
love_dude1984 is offline Offline
92 posts
since Aug 2008
Oct 29th, 2009
0
Re: Finding a specific character in a string
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.

ASP.NET Syntax (Toggle Plain Text)
  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 ?
ASP.NET Syntax (Toggle Plain Text)
  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; Oct 29th, 2009 at 5:26 am. Reason: wrong
Reputation Points: 11
Solved Threads: 17
Junior Poster
Kusno is offline Offline
191 posts
since Aug 2007
Oct 29th, 2009
0
Re: Finding a specific character in a string
You can split a string into array of sub strings based on delimiter character such as space, comma.

ASP.NET Syntax (Toggle Plain Text)
  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; Oct 29th, 2009 at 5:41 am.
Reputation Points: 165
Solved Threads: 113
Posting Pro
Ramesh S is offline Offline
580 posts
since Jun 2009
Oct 29th, 2009
0
Re: Finding a specific character in a string
Try this
ASP.NET Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 12
Posting Whiz in Training
carobee is offline Offline
209 posts
since Dec 2007
Oct 29th, 2009
0

Thank you..

Thank you frends...

i have got the solution.

Thanks agen..
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
love_dude1984 is offline Offline
92 posts
since Aug 2008
Oct 29th, 2009
0
Re: Finding a specific character in a string
Thank you frends...

i have got the solution.

Thanks agen..
Please close the thread by marking it as solved
Reputation Points: 10
Solved Threads: 12
Posting Whiz in Training
carobee is offline Offline
209 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Pop up window on condition in asp.net 2.0
Next Thread in ASP.NET Forum Timeline: Retrieve field value from GridView to compute total





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC