By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,619 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,619 IT Pros & Developers. It's quick & easy.

Splitting a string into an array using a STRING value

P: n/a
Hi all

basically its what i said in the subject. Would just like to know how to
split a string using a STRING value as the delimeter and not a CHAR as the
delimeter. Example: "I like Cheese", how would i get the following array:
strArray[0] = "I"; strArray[1] = "Cheese", using "like" as the delimeter

Thanks!
Jason
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Jason,

Try Regex.Split method.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jason" <c_*******@mighty.co.za> wrote in message
news:uz**************@TK2MSFTNGP12.phx.gbl...
Hi all

basically its what i said in the subject. Would just like to know how to
split a string using a STRING value as the delimeter and not a CHAR as the
delimeter. Example: "I like Cheese", how would i get the following array:
strArray[0] = "I"; strArray[1] = "Cheese", using "like" as the delimeter

Thanks!
Jason

Nov 15 '05 #2

P: n/a
You can use substring with a string arg, as follows:

Console.WriteLine("Enter a string to split:");
string inS = Console.ReadLine();
int inSL = inS.Length;

Console.WriteLine("Enter the string to split the first string:");
string sString = Console.ReadLine();
int sSL = sString.Length;

int pos = inS.IndexOf(sString);

if(pos >= 0)
{
Console.WriteLine("The strings are:");
string pre = inS.Substring(0, pos);
int preL = pre.Length;
Console.WriteLine("\"" + pre + "\"");

int postStart = sSL + preL;
int postEnd = inSL - postStart -1;
string post = inS.Substring(postStart, postEnd);

Console.WriteLine("\"" + post + "\"");
}
else
{
Console.WriteLine("Cannot find " + sString + " in " + inS);
}

"Miha Markic" <miha at rthand com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Jason,

Try Regex.Split method.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jason" <c_*******@mighty.co.za> wrote in message
news:uz**************@TK2MSFTNGP12.phx.gbl...
Hi all

basically its what i said in the subject. Would just like to know how to
split a string using a STRING value as the delimeter and not a CHAR as the delimeter. Example: "I like Cheese", how would i get the following array: strArray[0] = "I"; strArray[1] = "Cheese", using "like" as the delimeter

Thanks!
Jason


Nov 15 '05 #3

P: n/a
hmm yeh thanks
Have done this before. roundabout way, thanks for the reply! was wondering
if there was an easier way.

will try regex

Thanks
Jason

"Doug" <do**@home.org> wrote in message
news:jG******************@nwrddc03.gnilink.net...
You can use substring with a string arg, as follows:

Console.WriteLine("Enter a string to split:");
string inS = Console.ReadLine();
int inSL = inS.Length;

Console.WriteLine("Enter the string to split the first string:");
string sString = Console.ReadLine();
int sSL = sString.Length;

int pos = inS.IndexOf(sString);

if(pos >= 0)
{
Console.WriteLine("The strings are:");
string pre = inS.Substring(0, pos);
int preL = pre.Length;
Console.WriteLine("\"" + pre + "\"");

int postStart = sSL + preL;
int postEnd = inSL - postStart -1;
string post = inS.Substring(postStart, postEnd);

Console.WriteLine("\"" + post + "\"");
}
else
{
Console.WriteLine("Cannot find " + sString + " in " + inS);
}

"Miha Markic" <miha at rthand com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Jason,

Try Regex.Split method.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jason" <c_*******@mighty.co.za> wrote in message
news:uz**************@TK2MSFTNGP12.phx.gbl...
Hi all

basically its what i said in the subject. Would just like to know how to split a string using a STRING value as the delimeter and not a CHAR as the delimeter. Example: "I like Cheese", how would i get the following array: strArray[0] = "I"; strArray[1] = "Cheese", using "like" as the delimeter
Thanks!
Jason



Nov 15 '05 #4

P: n/a
On Mon, 17 Nov 2003 16:14:58 +0200, "Jason" <c_*******@mighty.co.za>
wrote:
hmm yeh thanks
Have done this before. roundabout way, thanks for the reply! was wondering
if there was an easier way.

will try regex


What's wrong with String.Split()?

String sSep = "SEPARATOR";
String asTokens[] = String.Split(myMasterString, CType(sSep, char[]);

--Jekke
Brain for hire. E-mail at jekke-at-insidejoke-dot-tv
Nov 15 '05 #5

P: n/a
Hi,

Did you actually try it - it should split text on multiple (each char) chars
and not on all of them togethe.
Example:
Dim sep As String = ",;"

Dim s As String() = "ab,cd;ef".Split(CType(sep, Char()))

Will produce an array with ab, cd, ef.
--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jekke, Just Jekke" <je***@REMOVEALLinsidejoke.tvCAPS> wrote in message
news:pg********************************@4ax.com...
On Mon, 17 Nov 2003 16:14:58 +0200, "Jason" <c_*******@mighty.co.za>
wrote:
hmm yeh thanks
Have done this before. roundabout way, thanks for the reply! was wonderingif there was an easier way.

will try regex


What's wrong with String.Split()?

String sSep = "SEPARATOR";
String asTokens[] = String.Split(myMasterString, CType(sSep, char[]);

--Jekke
Brain for hire. E-mail at jekke-at-insidejoke-dot-tv

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.