Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript 1

Status
Not open for further replies.

walkme40

Programmer
Apr 9, 2003
3
US
How do I read a text file as split values? The data is not delimited by commas. Some information is divided by space and other by the following: []

Please help. Thanks
 
I'm sure someone has a more economical way of doing this, but this should work.

<%@ Language=VBScript %>
<%Option Explicit%>
<%
dim str,x,h1,tmp,ending

str = &quot;Hello myst rin gis[]Thi[]s.&quot;
Response.Write &quot;<b>orig str is</b> &quot; & str & &quot;<hr>&quot;

str = replace(str,&quot;[]&quot;,&quot; &quot;,1,-1,1) ' replace all [] with spaces
Response.Write &quot;<br><b>String parsed is :</b>&quot;
x=1
do while x < len(str)
h1=Instr(x,str,&quot; &quot;,1)
if h1=0 then exit do 'if no spaces or [] then exit loop
tmp = mid(str,x,h1-x) 'parse string where character is found
Response.Write &quot;<br>&quot; & tmp
x = h1+1
loop

'special case for last word in sentence
ending = instrRev(str,&quot; &quot;,len(str),1)
if ending then
tmp=mid(str,ending,len(str))
Response.Write &quot;<br>&quot; & tmp
end if
%>
 
Thank you. I will try this. Here is a sample of what I have before your email. It started failing. :(

LineRead=TRIM(LineRead)

if left(LineRead,3) =&quot;Tex&quot; then
response.write &quot;<table border='1' cellpadding='0' cellspacing='0' width='650'>&quot;
'LineRead= &quot;Tex&quot; & LineRead
flag_data=1

end if

if flag_data=1 then
'This is used to remove bad values
for i = 1 to 15
LineRead=replace(LineRead, &quot; &quot;, &quot; &quot;)
next
LineRead=replace(LineRead,&quot; &quot;, &quot;-&quot;)
LineRead=replace(LineRead,chr(9), &quot;-&quot;)
LineRead=replace(LineRead,&quot;--&quot;, &quot;-&quot;)
'response.write lineread & &quot;<br>&quot;


SplitValues = Split(LineRead, &quot;-&quot;, -1, 1)
response.write &quot;<tr>&quot;


 
Ikaliar,

I still cannot get it to work. Here is an example of the string.

1.00 0.095 6.1 0.006
2.00 0.095 6.1 0.009

Can anyone help. I get type mismatch error then I get a subscript out of range error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top