English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i am using the split function but some of my data is separated by a space some by a tab. I have set it up to recognise spaces but cant figure out how to get both space and tab recognised.

strinarr = linstrin.Split((" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)

The above works well for spaces.
Visual Basic 2005 Express Edition (from internet)

CHEERS!!!!!!!!!!!!!!!!!!!!!!!

2007-12-30 08:01:49 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

Yeah but how do i do both?

2007-12-30 08:08:56 · update #1

4 answers

VB haws a number of built in constants which you can use with the split function

vbTab = chr(9) = TAB
vbCr = chr(13) = Carriage return
vbCrLf = chr(13) + chr(10) Carriage Return / Line Feed

these are three of the most used constants.

You can also use a string variable and assign what ever delimiter you wish to use by converting ASCII code into characters. You can even assign a string and slpit on key words.

If you are trying to split a string which has two or more delimiters I suggest that you convert the delimiters to the same type. Once you have converted your delimiters you can perform a single split function.

Dim str As String = "Test this string,which has,both spaces and commas"
Dim ay() As String
Dim myDelim, myOldDelim As String

myDelim = ","
myOldDelim = " "

str = str.Replace(myOldDelim, myDelim)

ay = Split(str, myDelim)

This code uses the replace function to find and replace one delimiter type with another . This assumes that you donot have adjacent delimiter types like a space ext to a comma which will get converted into two commas. If this is the case you can add the following code just before splitting

Do While (str.Contains(myDelim + myDelim))
str = str.Replace((myDelim + myDelim), myDelim)
Loop
This loop looks for a double delimiter (adjacent commas like ,,,) and will replace two commas with a single comma until no more double commas are detected.

2007-12-30 09:03:19 · answer #1 · answered by MarkG 7 · 0 0

If you already have a means of determining the SPACE character, I would use the "REPLACE" function and convert those spaces to TABS first.

sVar = Replace(InVariable, Chr(32), Chr(9))

FYI ... as SPACE is a very bad delimiter, as it is too commonly used. I would really look at why you are using a space character.

2007-12-30 08:18:38 · answer #2 · answered by LaCostaSteve 2 · 0 0

Use Regex and create a pattern match that will search for either a space or a tab.

Try this:

Add Imports System.Text.RegularExpressions at top.

strinarr = Regex.Split(linstrin, "\s+")

2007-12-30 08:11:49 · answer #3 · answered by Theseus 4 · 0 0

suitable this is elementary suggestions to do it... you need to use right here code on your Form_Load() journey. If App.PrevInstance = real Then ShowPrevInstance end end If The above code would be carried out mutually as the appliance would be released. in case you upload the line "ShowPrevInstance" then this is going to concentration the present working occasion of your utility and the "end" line will avert it from working it back (yet yet another occasion). desire this facilitates. reliable fulfillment.

2016-12-18 12:33:59 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers