Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net: can you split a string by a string

for example, can i do this:

split = temp_string.Split("<beginning of record>") 

those of you recommended:

split = Regex.Split(temp_string, "< beginning of record >") 

its not working. its just returning the first char "<"

and those of you that recommended:

Dim myDelims As String() = New String(){"< beginning of record >"} split = temp_string.Split(myDelims, StringSplitOptions.None) 

this is not working either. it's also returning just the first char

like image 984
Alex Gordon Avatar asked Oct 28 '09 18:10

Alex Gordon


People also ask

How do I split a string into string?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How cut a string in VB net?

Try Mid(txtCpu. Text, Len(txtCpu. Text) - 6, 3) - the last parameter is the length of the string you want, not an absolute position.

Can we split a string?

Python String split() MethodThe split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.


1 Answers

Try this:

string[] myDelims = new string[] { "<beginning of record>" }; split = temp_string.Split(myDelims,StringSplitOptions.None); 

Running this through a code converter results in this:

Dim myDelims As String() = New String() { "<beginning of record>" } split = temp_string.Split(myDelims, StringSplitOptions.None) 

You may also need to escape the chevrons, like this:

"\< beginning of record \>" 
like image 149
Matthew Jones Avatar answered Sep 21 '22 14:09

Matthew Jones