开发者

ASP Left function issue

I have this code and something odd happening when I'm running it.

I have field number like 101512 up to 101520. I've used LEFT function to get rid of last two digits and keep the 1015. When i runn loop function for th开发者_如何学Ce first one it gives me 1015 but for the rest it gives me 101 an it elminates the last digit like this:

d = Split(Request("field"),",")  
For i = 1 To UBound(d)  
  Responce.Write(Left(d(i),4))  
Next

Results

1015  
101  
101  
101  
...

Does anybody have any idea what is going on?


My guess is that Request("field") may be returning a string like the following:

101520, 101521, 101522

Note the space after each comma. Thus when you apply Left() and print the value to your HTML output you don't notice the space but you only see three digits as the space counted as the first digit

One thing to try to see if this is the case is to change the code to the following:

Left(Trim(d(i)), 4)

That way any spaces around the value are removed before Left() is applied.


Correct way to iterate over "multi value" request item is actually:

For i = 0 To Request("field").Count-1
   Response.Write(Request("field").Item(i) & "<br />")
Next

This will iterate the actual values without using split at all..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜