Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 Parsing VB script line feed

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 13:44:45
Hello,
Am have a slight problem parsing a request.form object results for VB Script line feeds.

PROBLEM:
If i put numbers in a textbox seperated by a comma e.g. 2452452,42542542,24524524 once i retrieve and iterate through the results set i can easily parse them. Using the split funtion and checking through each value in an array

e.g.


numbers = request.form("results")
split(numbers)
total = ubound(numbers)

for i = 0 to total
response.write(numbers(i))
next


However, when i use a line feed. e.g.

45245245,
25254254,
254254254

The result set adds a space before the number(i) value

I have tried using both replace and trim function, to remove the space, but it appears the space is a server encode character.

I tried using the server.HTMLEncode(number(i)) to see what the value is, but nothing is written.

PROBLEM
The result set no longer is a numeric value. How do i solve this ?

QUITE COMPLEX

Any ideas, thanks

Afrika

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 15:07:42
In VB there is a CSTR function. Try that for VBScript too.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 15:25:10
cstr means to convert to a string.

I had tried it before, something like

numbers = request.form("results")
split(numbers)
total = ubound(numbers)

for i = 0 to total
cstr(numbers(i))
response.write(numbers(i))
next


Still does not remove the invalid character.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 15:36:39
numbers = request.form("results")
split(numbers)
total = ubound(numbers)

for i = 0 to total
response.write(CSTR(numbers(i)))
next


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 16:00:07
Hi Peter, i ran a couple of tests,

...still does not remove the invalid character. I get something like this

FAILURE : 23480353tyrt82335/9,234803312325s0/9,234803312325s0/9,234803312325=0/9,23480331232500/2,2348033123250.2348033123250/2,JKLKJKLJKLLKJ/9,2345902222222/1,2348033123250./2, 2348023265551/4, 2348023265551/4, 2348023265551/4

The code above is a result set, of values that dont meet the numeric character or length above 13 characters, which is the maximum length for a phone number value.

The last sets in red are from "line feed" values, if you notice there is a space before the numbers and the value "/4" tells me its longer than 13 characters, (reason for failure to meet the test)

I tried using cstr to remove it and also tried trim and replace and it still does not work.

Afrika
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 16:07:09
numbers = request.form("results")
split(numbers)
total = ubound(numbers)

for i = 0 to total
response.write(ASC(LEFT(CSTR(numbers(i)), 1)))
next


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 16:21:45
I get the value 13.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 16:25:22
That means that the first character is CR.

numbers = request.form("results")
split(numbers)
total = ubound(numbers)

for i = 0 to total
response.write(REPLACE(CSTR(numbers(i)), CHR(13), ''))
next


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 16:32:24
Since your code, or VBscript, obviously adds a CR to the output, replace the CR with empty string as my previous post.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 16:40:43
Sorry am a bit lost here.

1st of all, your code is meant to read
response.write(REPLACE(CSTR(numbers(i)), CHR(13), ""))
not
response.write(REPLACE(CSTR(numbers(i)), CHR(13), ''))

As single quotation marks are for variables in SQL not VB script

Secondly,
What do you mean replace the CR with an empty string. Am a bit lost here

rgds
Ehi
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 16:43:30
Instead of "CR" am guessing you mean the value for carriage return constats which is Chr(13) ?

Is this what you mean ?

... Am still testing the code
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 16:46:24
Yes. Sorry. I am still in "SQL mode". The replacement should be two double quotes.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 16:54:23
Yesssssssssssssssss !!!!!!!!!!!!!!!!!!!!!

IT WORKED !

Peter, i must admit. you are a genius. Great Guy !!!

Thanks a great deal.

This is the final code


check(i) = (REPLACE(CSTR(check(i)), CHR(13), ""))
check(i) = (REPLACE(CSTR(check(i)), CHR(10), ""))


I noticed a change of failed values in my test, for (failed numbers) which is in my 3rd post above, ...
... The value changed from
, 23802365551/4 to , 23802365551/2 And the space was still there.

So i looked up the values for carriage return and linefeed (Newline) values and as you said, it was Chr(13) & Chr(10)

So i replaced them, and it works like a charm

Thanks a great deal

Ehi
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 17:03:27
Happy to help you.
Good luck.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-05 : 17:06:44
Am very grateful, thanks a great deal

Here's one on me
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-12-06 : 03:12:25
hi Peter,
i just found another way of achieving the same results

check(i) = (REPLACE(CSTR(check(i)), vbCrLf, ""))

Have a great day
Ehi
Go to Top of Page
   

- Advertisement -