Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Not able to split astring-need ur help

I have a text file where i have to read string and inserted to database...
For example :
I have following things:
Name:Sujha
Age 23
Phone : 90886543...

Now,Iam able to split this whole file and insert into DB..The problem is if i have
Name:Sudha...
It is written in the Database..But if i have..
Name Sudha(without any delimiters) iam not able to write it in database,Also
If i have Name: Sudha(with a space)iam not able to write it in database

All these values are in a single text file Where i have to read all values and insert into DataBase..

The Code i use is...

fields = Split(lines(line_num), delimiter)
'fields = lines(line_num)

For field_num = LBound(fields) To UBound(fields)

'l_strFind = InStr(lines(line_num), "EXPIRY DATE")


Select Case fields(field_num)
'Select Case l_strFind

Case Is = "Name:"
For field_num1 = LBound(fields) To UBound(fields)
If (field_num1 < UBound(fields)) Then
' MsgBox fields(field_num + 1)
yourRef = Trim(fields(field_num + 1))
'field_num = field_num + 1
Exit For
Else
yourRef = Trim(fields(field_num))
End If
Next

Please help Me out Vb Guru'S...
[1685 byte] By [sujha] at [2007-11-11 10:20:11]
# 1 Re: Not able to split astring-need ur help
Try something like this:
lines(line_num) = Trim(lines(line_num))

'remove excess spaces without loosing the seperation
Do While InStr(lines(line_num), " ")
lines(line_num) = Replace(lines(line_num), " ", " ")
Loop
lines(line_num) = Replace(lines(line_num), " : ", ":")
lines(line_num) = Replace(lines(line_num), ": ", ":")
lines(line_num) = Replace(lines(line_num), " :", ":")
If InStr(lines(line_num), ":") = 0 Then
Mid(lines(line_num), InStr(lines(line_num), " "), 1) = ":"
End If
Ron Weller at 2007-11-11 17:22:46 >
# 2 Re: Not able to split astring-need ur help
Thank u So Much For ur immediate response,the code works exactly right as i expects..
sujha at 2007-11-11 17:23:54 >