|
-
Aug 19th, 2012, 11:06 AM
#1
Thread Starter
Frenzied Member
Spliting a string
Here is an example of a string that I am wishing to use:
tourney ffa team ctf clan arena
I am wanting to split it into an array.
I am currently using this code:
Code:
stringCurrentGameTypes = Split(stringTypeList, " ")
This works. I am wanting to make an exception to certain strings. "clan arena" is one.
Rather than having two entries, one as "clan" and the other as "arena", I would like "clan arena" to be one entry in the array.
How would the best way be to go about this?
-
Aug 19th, 2012, 11:10 AM
#2
Re: Spliting a string
Are all the strings this convenient, ie. 1,1,1,1,2 words? That's doable. If it varies, eg. 2,1,1,1,1 or 1,1,1,1,1 then we've got a problem!
-
Aug 19th, 2012, 06:13 PM
#3
Re: Spliting a string
you can work around it with regex:
vb.net Code:
Imports System.Text.RegularExpressions Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim s As String = "tourney ffa team ctf ""clan arena""" For Each str As String In Regex.Split(s, "(?<!""\w+?)\s(?!\w+?"")") MsgBox(str.Replace("""", "")) Next End Sub End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 19th, 2012, 11:07 PM
#4
Thread Starter
Frenzied Member
Re: Spliting a string
If it varies, eg. 2,1,1,1,1 or 1,1,1,1,1 then we've got a problem!
Unfortunately... it varies
Any other ideas on how to accomplish this?
Maybe add all the items to the array and then call a 'Clean up' function that loops through the array, finds the positions of the 'clan' and 'arena' entries and then combines them into one entry.
Could this be the way to do it?
Last edited by Simon Canning; Aug 19th, 2012 at 11:25 PM.
-
Aug 20th, 2012, 12:59 AM
#5
Re: Spliting a string
If that is the only exception, then I would simply search my splitted string for clan and arena and merge the two, however if there are a lot more exceptions I would create a small tokenizer and parser seeing as your string doesn't have delimiters.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|