SplitString
-
Are there any possibilities to split string like this : "hello world" "aaa bbb" "ccc" 10.5 20.1 30.4 it must be split like this : hello world aaa bbb ccc 10.5 20.1 30.4 Thx...
-
Are there any possibilities to split string like this : "hello world" "aaa bbb" "ccc" 10.5 20.1 30.4 it must be split like this : hello world aaa bbb ccc 10.5 20.1 30.4 Thx...
namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string str = string.Empty; str="bbb ccc ddd 10.5 20.1 30.4"; string[] sstring = str.Split(' '); foreach (string s in sstring) { Console.WriteLine(s); } } } }
Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
-
namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string str = string.Empty; str="bbb ccc ddd 10.5 20.1 30.4"; string[] sstring = str.Split(' '); foreach (string s in sstring) { Console.WriteLine(s); } } } }
Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
-
Are there any possibilities to split string like this : "hello world" "aaa bbb" "ccc" 10.5 20.1 30.4 it must be split like this : hello world aaa bbb ccc 10.5 20.1 30.4 Thx...
by coding u can do this like that
string[] mainstring;
string[] s = string.Empty;
string[] t = string.Empty;
s = yourstring.spilt('"');for(int i=1;i<s.length;i++)>
{
if(i%2 != 0)
{
mianstring[i-1] = s[i]
}
int i = mainstring.length;
t = mainstring[i].split(' ');
i = i-1'
foreach(string s in t)
{
mainstring[i+1] = s;}
}wasim khan
-
Please see my question again. Note the quote "aaa bbb" "ccc dddd" 10.1 20.2 You cannot just split using space.
stancrm wrote:
"aaa bbb" "ccc dddd" 10.1 20.2
let me know how did you creting a string in this way ???:confused:
Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
-
stancrm wrote:
"aaa bbb" "ccc dddd" 10.1 20.2
let me know how did you creting a string in this way ???:confused:
Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
-
1. split the string use space character 2. trim each returned string use " character i hope this usefull
dhaim program is hobby that make some money as side effect :)
-
Are there any possibilities to split string like this : "hello world" "aaa bbb" "ccc" 10.5 20.1 30.4 it must be split like this : hello world aaa bbb ccc 10.5 20.1 30.4 Thx...
Not tested:
public List<string> SplitLine(string line)
{
List<string> items = new List<string>();MatchCollection matchCollection = Regex.Matches(line, "\"[^\"]*\"|[^\"]*");
foreach (Match match in matchCollection)
{
string group = match.Value.Trim();
if (group != string.Empty)
{
if (group[0] == '"')
{
items.Add(group.Trim(new char[] {'"'}));
}
else
{
//items.AddRange(group.Split(new char[] {'"'}, StringSplitOptions.RemoveEmptyEntries)); sorry, should be
items.AddRange(group.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries));
}
}
}
return items;
}Hope this helps.
modified on Thursday, June 26, 2008 7:48 AM
-
Not tested:
public List<string> SplitLine(string line)
{
List<string> items = new List<string>();MatchCollection matchCollection = Regex.Matches(line, "\"[^\"]*\"|[^\"]*");
foreach (Match match in matchCollection)
{
string group = match.Value.Trim();
if (group != string.Empty)
{
if (group[0] == '"')
{
items.Add(group.Trim(new char[] {'"'}));
}
else
{
//items.AddRange(group.Split(new char[] {'"'}, StringSplitOptions.RemoveEmptyEntries)); sorry, should be
items.AddRange(group.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries));
}
}
}
return items;
}Hope this helps.
modified on Thursday, June 26, 2008 7:48 AM
I just found the answer.
static string[] ParseStringUsingRegex(string input)
{
Regex regex = new Regex("\"([^\"]+?)\" ?|([^ ]+) ?| ");
MatchCollection matches = regex.Matches(input);string[] result = new string[matches.Count];
for(int i = 0; i < matches.Count; i++)
{
Match match = matches[i];
result[i] = match.ToString().Replace("\"", "").Trim();
}
return result;
}