split function
-
hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following
Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1)
now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company
-
hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following
Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1)
now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company
Change the separator if possible, otherwise first replace your separator string with a character separator and then perform spliting operation using ur new character separator. You can use Replace function to replace strings or characters in a string with other strings or characters.
-
Change the separator if possible, otherwise first replace your separator string with a character separator and then perform spliting operation using ur new character separator. You can use Replace function to replace strings or characters in a string with other strings or characters.
hi iprasad2007, i already know this thing but i want to split my string on the basis of its substring not on any character. sorry,but this is not the answer of my question.
Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company
-
hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following
Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1)
now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company
The problem with this is that the split function expects a array of chars and when you give it a string it just uses the first char (in this case the "a"). I don't imidiatly know how you could solve this but I have a workaround:
Dim path, str, seperat As String
str = "0\0\0\0and--->Caption1"
seperat = "and--->"
Dim Title As String
str = str.Replace(seperat, "~")
Dim ItemInfo() As String = str.Split("~")
path = ItemInfo(0)
Title = ItemInfo(1)basicly the same code just that I replace the seperat string with "~" before splitting. This way ther is only 1 char to split on (or string of 1 char) and it works perfectly hope this helps
-
The problem with this is that the split function expects a array of chars and when you give it a string it just uses the first char (in this case the "a"). I don't imidiatly know how you could solve this but I have a workaround:
Dim path, str, seperat As String
str = "0\0\0\0and--->Caption1"
seperat = "and--->"
Dim Title As String
str = str.Replace(seperat, "~")
Dim ItemInfo() As String = str.Split("~")
path = ItemInfo(0)
Title = ItemInfo(1)basicly the same code just that I replace the seperat string with "~" before splitting. This way ther is only 1 char to split on (or string of 1 char) and it works perfectly hope this helps
Im not sure if you want to use pure .Net code or not, but if you dont you can do this:
Dim path, str, seperat As String str = "0\0\0\0and--->Caption1" seperat = "and--->" Dim Title As String Dim ItemInfo() As String = _**Split(str, seperat)**_ path = ItemInfo(0) Title = ItemInfo(1)
The piece of code in bold italic is the VB6 way of doing it using strings and as you can see can it be used in VB .Net once the Microsoft.VisualBacic Namespace is included Hope this helps. -
Im not sure if you want to use pure .Net code or not, but if you dont you can do this:
Dim path, str, seperat As String str = "0\0\0\0and--->Caption1" seperat = "and--->" Dim Title As String Dim ItemInfo() As String = _**Split(str, seperat)**_ path = ItemInfo(0) Title = ItemInfo(1)
The piece of code in bold italic is the VB6 way of doing it using strings and as you can see can it be used in VB .Net once the Microsoft.VisualBacic Namespace is included Hope this helps.Thanks keith, its work
Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company
-
hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following
Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1)
now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company
I believe the function you are looking for is a tokenize function (split a string by a delimiter(separator)) EDIT: I tried to write one here for you but got confused, I will tommorow when I got more time. EDIT AGAIN: Mine doesn't fit in memory. -- modified at 3:12 Saturday 1st September, 2007
All of my programs are downloadable at fahadsadah.co.nr