469,934 Members | 2,122 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Splitting a String

Using Vb.net 2005,
I want to read each part in this string in an array (splitting the string)
-----------
A1/EXT "BK82 LB73 21233" 105 061018 1804
-----------
That Code that i used is as follow:

Dim s As String, h As String
Dim delim(1) As Char
delim(0) = "/"
delim(1) = " "

Dim f() As String
s = A1/EXT ""BK82 LB73 21233"" 105 061018 1804
f = s.Split(delim)
-----------
The problem that I m facing is as follow :
even what is inside the double quotes is devided into parts
what should i add to my code (or any other solution),
in order to keep what is inside the "" with splitting
Oct 29 '06 #1
2 1294
xtab
6
Hi, You contacted me off-forum re this one, so I was a bit surprised and confused about why you've gone about your second code block in such a roundabout way.

A very small variation of what I suggested seems to work just fine. That is, it finds the quotes, removes them, pulls out the block of code you wanted to select and displays it.

Expand|Select|Wrap|Line Numbers
  1. Dim result As New ArrayList
  2.         Dim checkStr As String = "A1/EXT ""BK82 LB73 21233"" 105 061018 1804"
  3.  
  4.         If checkStr.Contains(Chr(34)) Then
  5.             Dim first As Integer = checkStr.IndexOf(Chr(34)) + 1
  6.             Dim last As Integer = checkStr.LastIndexOf(Chr(34))
  7.             result.Add(checkStr.Substring(first, last - first))
  8.         End If
  9.         For Each s2 As String In result
  10.             Console.WriteLine(s2)
  11.         Next
Hope this helps
Oct 29 '06 #2
xtab
6
Sorry, forgot to mention that this line in your code sample:

s = A1/EXT ""BK82 LB73 21233"" 105 061018 1804

won't compile because you need to enclose the whole string in quotes.

(I made that change in my suggestion in the previous post)
Oct 29 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by qwweeeit | last post: by
5 posts views Thread by fatted | last post: by
2 posts views Thread by Trint Smith | last post: by
20 posts views Thread by Opettaja | last post: by
6 posts views Thread by HMS Surprise | last post: by
2 posts views Thread by shadow_ | last post: by
4 posts views Thread by yogi_bear_79 | last post: by
37 posts views Thread by xyz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.