Im not sure if anyone here knows PHP, but there is a command called "explode" to break apart a string. Is there any thing similar to this in Visual Basic?
Printable View
Im not sure if anyone here knows PHP, but there is a command called "explode" to break apart a string. Is there any thing similar to this in Visual Basic?
The Split command is what you're looking for.
Depends on the end goal. If you need to break it apart by a delimiter, than use the Split() function. You could also use the .ToCharArray() function to break it apart into a string array, each member containing one character of the string.
my goal is to take the output of a shell command and use only certain parts of it
Would i use split() for that?
and by the way, its going to need to be broken apart by spaces.
Then yes. Bring it in as a string. I'll call it myStr. Then run this command:
Dim strArray() As String = myStr.Split(" ")
then when i want to retrieve it, what variable would i use?
Split would work for that, depending on if the return string had consistant delimiters. You could also use the regular expression component if your parsing needs were more complex.
You would call strArray and whatever element you want. So if you wanted the second element, you'd call for strArray(1), since arrays are 0-based.
ok. thanks a lot for the quick replies, ill try that when i get back home and reply whether it worked or not.
I guess its very similar to PHP :)
one more thing,
the string that i want to break apart would be set equal to StrArray(), right?
Yes, and its elements would be strArray(0) to strArray(x) depending on how many elements it had.
Ok, thanks a lot guys
I am trying to parse a string who's delimiter is a newline. Do you know how I could do this in VBScript?
Thanks in advance!!
This is a VB.NET forum, not VBScript. If you take a look at the site home page it tells you what each forum is for. There is one dedicated to VBScript and this is not it.Quote:
Originally Posted by chankew
I want to split a string on basis of a repeated string, or may be a delimiter composed of more than one characters.
Is there any function available to do that.
Substring is also a function but it takes integer index values which is not applicable to my case?