how to split a string without using split function in c#
without using any other inbuilt function in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mageshwaran RPosted Nov 15, 2019, 5:02 AM
praveen kumarPosted Jan 21, 2019, 10:20 AM
string str = Console.ReadLine();
ArrayList ar = new ArrayList();
// List
string temp = "";
for (int i = 0; i
if (str[i] != ' ')
{
temp += str[i];
if (i == (str.Length - 1))
ar.Add(temp);
continue;
}
ar.Add(temp);
temp = "";
}
foreach (string s in ar)
{
Console.WriteLine(s);
}
Console.ReadLine();
Jaganathan BantheswaranPosted Oct 7, 2013, 6:32 AM
string strRegex = @"[\s]+"; // splits by space.
RegexOptions myRegexOptions = RegexOptions.IgnoreCase | RegexOptions.Multiline;
Regex myRegex = new Regex(strRegex, myRegexOptions);
string strTargetString = @"Example String.";
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
var str = myMatch.Group[1].Value; //Add this value to list.
// Add your code here
}
}
nishant ranjanPosted Oct 7, 2013, 4:02 AM
ArrayList ar = new ArrayList();
string tmp = "";
for (int i = 0; i
if (str[i] != ' ')
{
tmp = tmp + str[i];
continue;
}
ar.Add(tmp);
tmp = "";
}
foreach (string a in ar)
{
Console.WriteLine(a );
}
Console.ReadLine();
here i have split based on space.