ASP Left function issue - vbscript

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 the 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..

Related

Replace the last character or number of a string | Freemarker

I need to check if the last number of character of a ${string} is equal to 9.
The string or numbers that I have to handle with is something 831, 519 or 1351.
However I dont know how do do it properly. I tried already something like:
${string?replace((string.length)-1,"9")}
At the end there should be instead of 831 --> 839 or 1351 --> 1359 and so on.
Any sugestions about how I can archive this ?
Oh and by the way. If I use the fuction above this error massage comes up:
Script error: You have used ?number on a string-value which is not a number (or is empty or contains spaces).
And what I tried also was:
code snippet
Because the original number is somethink like 831.896.
You could use string slicing to keep all characters except for the last one like this:
<#assign string = "1234">
<#assign string = string[0..<string?length-1] + "9">
${string}
Results in:
1239
Since you want to replace that thing, use ?replace. This replaces the last character with 9, if the last character is a digit that's not already 9:
${s?replace("[0-8]$", '9', 'r')}

Autocad Diesel IF expression for sheet number tag

I am trying to automate a sheet tag with a Diesel expression in AutoCad.
This gets me the twelfth character in the drawing name. But as soon as I get to sheet 10 this will say its sheet 0.
$(substr,$(getvar,dwgname),12,1)
Does anyone know a way to get an If statement to see if the eleventh character is a 0 then run the above code else run $(substr,$(getvar,dwgname),11,2)
This is something i have tried.
$(IF,substr,$(getvar,dwgname),11,1)="0"$(substr,$(getvar,dwgname),11,2,substr,$(getvar,dwgname),12,1)
This appears to be similar to excel formulas. Thanks for any help.
The format for the Diesel if statement is:
$(if, expr, dotrue [, dofalse])
If the expr is nonzero, it evaluates and returns dotrue.
You seem to have a lot more going on in your sample. Do the full evaluation (does the 11th character equal 0 in the expr portion and then set your returns, the false portion is optional and can be omitted.
Here is the Diesel expression i got working for auto sheet no. in autocad fields.
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1))
$(if,$(substr,$(getvar,dwgname),11,1)"0" = Does character 11 = 0
,$(substr,$(getvar,dwgname),11,2) = if no then take character 11 and the next char.
,$(substr,$(getvar,dwgname),12,1)) = if char 11 is = to 0 then take only char 11.
I use two fields in my autocad border. One for the filename without the sheet no and this one for only the sheet number.
Example filename: A150225_S001.dwg
$(substr,$(getvar,dwgname),1, 7) = Use char from position 1 to 7. "A150225"
$(if,$(substr,$(getvar,dwgname),11,1)"0",$(substr,$(getvar,dwgname),11,2),$(substr,$(getvar,dwgname),12,1)) = Use sheet no. at end of filename string. "1"
Hope this helps anyone looking to do something similar.

Soundex returns 0 for every character

I have this function which converts a word to a soundex value, but it is returning all letters as 0. My last name, Smith, should by S530, but returns S000, for example.
Link for code (since it's too long to put on here): http://pastebin.com/9hESxV7P
I had it log the value of letterArray and it does evaluate to an array of all the letters in my last name. It has to be something in the for ... in loop. Any help would be great. Thanks!
changing this line
let trimmedWord = word.uppercaseString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
it produce S530

Automatically increment filename VideoWriter MATLAB

I have MATLAB set to record three webcams at the same time. I want to capture and save each feed to a file and automatically increment it the file name, it will be replaced by experiment_0001.avi, followed by experiment_0002.avi, etc.
My code looks like this at the moment
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
avi1 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_002.AVI');
avi2 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI');
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
and I am incrementing the 002 each time.
Any thoughts on how to implement this efficiently?
Thanks.
dont forget matlab has some roots to C programming language. That means things like sprintf will work
so since you are printing out an integer value zero padded to 3 spaces you would need something like this sprintf('%03d',n) then % means there is a value to print that isn't text. 0 means zero pad on the left, 3 means pad to 3 digits, d means the number itself is an integer
just use sprintf in place of a string. the s means String print formatted. so it will output a string. here is an idea of what you might do
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
for (n=1:2:max_num_captures)
avi1 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_%03d.AVI',n));
avi2 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI',n));
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
end

How to count the number of space-delimited substrings in a string

Dim str as String
str = "30 40 50 60"
I want to count the number of substrings.
Expected Output: 4
(because there are 4 total values: 30, 40, 50, 60)
How can I accomplish this in VB6?
You could try this:
arrStr = Split(str, " ")
strCnt = UBound(arrStr) + 1
msgBox strCnt
Of course, if you've got Option Explicit set (which you should..) then declare the variables above first..
Your request doesn't make any sense. A string is a sequence of text. The fact that that sequence of text contains numbers separated by spaces is quite irrelevant. Your string looks like this:
30 40 50 60
There are not 4 separate values, there is only one value, shown aboveā€”a single string.
You could also view the string as containing 11 individual characters, so it could be argued that the "count" of the string would be 11, but this doesn't get you any further towards your goal.
In order to get the result that you expect, you need to split the string into multiple strings at each space, producing 4 separate strings, each containing a 2-digit numeric value.
Of course, the real question is why you're storing this value in a string in the first place. If they're numeric values, you should store them in an array (for example, an array of Integers). Then you can easily obtain the number of elements in the array using the LBound() and UBound() functions.
I agree with everything Cody stated.
If you really wanted to you could loop through the string character by character and count the number of times you find your delimiter. In your example, it is space delimited, so you would simply count the number of spaces and add 1, but as Cody stated, those are not separate values..
Are you trying to parse text here or what? Regardless, I think what you really need to do is store your data into an array. Make your life easier, not more difficult.

Resources