Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Getting Individual String

  Asked By: Lorenzo    Date: Dec 09    Category: Asp.net    Views: 882
  

I have a srting say

str = "abc,def,hij,klm"

if I want the values in a Loop say

s = "abc" first time
s="def" second time
s="hij" third time How do I do this??

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Kerry Wright     Answered On: Dec 09

Here is a possible solution:

string str = "abc,def,hij,klm";
foreach (string s in str.Split( new char[] {','} ))
Response.Write(s);

 
Answer #2    Answered By: Miriam Green     Answered On: Dec 09


using System.Text.RegularExpressions;



Regex r = new Regex("(,)"); // Split on hyphens.

string[] s = r.Split("abc,def,ghi,jklm,no,pq,rstuvw,xyz");

string[] s2 = new string[(int)Math.Round((decimal)s.Length/(decimal)2)]; // you
might have to add a 1 to the length, or you might
//as well add it anyway ...it can't hurt

for (int i =0; i<s.Length;i++)

{

if (i % 2 == 0)

s2[i/2] = s[i];

}

for (int i =0; i<s2.Length;i++)

{

Response.Write(s2[i] + "<br>");

}


 
Answer #3    Answered By: Alberta Miller     Answered On: Dec 09


str = "abc,def,ghi,jklm,no,pq,rstuvw,xyz";

string[] s = str.Split(',');

for (int i =0; i<s.Length;i++)

{

Response.Write(s[i] + "<br>");

}

 
Answer #4    Answered By: Debbie Reyes     Answered On: Dec 09



string[] sArr = str.Split(',');
foreach(string s in sArr)
{
Response.Write(s);
}

 
Answer #5    Answered By: Leroy Schmidt     Answered On: Dec 09

Use str.Split(",") to make an array.

Then loop  through the array.

 
Didn't find what you were looking for? Find more on Getting Individual String Or get search suggestion and latest updates.




Tagged: