read split string with substring(fixed length)

Joined
Jun 17, 2014
Messages
7
Programming Experience
Beginner
i'm still new about vb.net, and i want to ask a question about read string with substring(fixed length)

and here is the string.

#T|ABudiCityC |ATutiCityCD|BMan |BWoman|

header=#T(length 2)
sub = A,B(length 1)
Name= Budi,Tuti (length 4)
City= cityC ,cityCD (length 6)
gender= man , woman(length 6)

the Header length=2, for A sub is 11, and B sub is 6

and here is the delimiter "|"

so this is the script what i mean(i think, don't know if it right though)

if header.substring(0,2)= "#T" then
if sub.substring(0,1)"A" then
name.substring(1,4)
city.substring(5,7)
else if sub.substring(0,2)="B" then
gender.substring(1,5)
end if
end if

help me please, thanks
smile.gif

 
Since you have a separator ("|"), you don't have to go with lengths.

Dim elements() As String = MyString.Split("|")
If elements(0) = "#T" Then...
If elements(1).First = "A" Then...

etc...

The string format is really weird though, you have info from a single field spread over multiple columns?
 
Since you have a separator ("|"), you don't have to go with lengths.

Dim elements() As String = MyString.Split("|")
If elements(0) = "#T" Then...
If elements(1).First = "A" Then...

etc...

The string format is really weird though, you have info from a single field spread over multiple columns?

yeah, in "A" part there's part name and city, and in "B" part there's gender

my though is, after meet "|", it will read the next part using "substring", that's why i used "fixed legth" to read the string

any idea?
thanks :)
 
Back
Top