Classic ASP - Check how many numbers are in a variable - asp-classic

Im wondering if someone could help me.
I need to get the amount of numbers in a variable.
So for instance:
number = Int(34324)
Would contain 5 and so on.
Cheers

Use the Len() function:
digitCount = Len(CStr(number))

Related

Detect and replace multiple leading zeros in string

I'm working with an address database. For further cleaning I need to identify the leading zeros that are stored in the string containing the door number. So a clean and friendly case would be something like 7/5 - where 7 would be the house number, 5 the door number.
The problem is that in some cases, there are leading zeros involved - not only at the beginning of the string, but also in the middle. And of course, there are also "normal" and necessary zeros. So I could have an address like 7/50, where the zero is totally fine and should stay there. But I could also have 007/05, where all the zeros need to go away. So the only pattern I can think of is to check wheter there is a number greater than zero before that zero. If no, then delete that zero, if yes, keep it.
Is there any function to achieve something like this? Or would this require something custom built? Thanks for any suggestions!
You can try the code below base R option using gsub
> gsub("\\b0+", "", s)
[1] "1/1001001" "7/50" "7/50" "7/5" "7/5"
with given
s <- c("01/1001001", "07/050", "0007/50", "7/5", "007/05")
Maybe a negative look behind will help
x <- c("7/50", "7/5", "007/05")
stringr::str_remove_all(x, "\\b(?<![1-9])0+")
# [1] "7/50" "7/5" "7/5"
Hard to say for sure with such a limited set of test cases.

Getting value of some elemnets by having their difference

I am currently working on particular algorithm, but I face with a problem that I'm not sure what I have to do to resolve it. I appreciate if anyone helps me out.
There are some objects{O1,O2,O3,.....}, each of them has a value that we don't know about its amount, we call them {V1,V2,V3,....} also there is another element we call it w(w1,w2,w3.....) which shows the difference between values, I mean w1=v2-v1, w2=v3-v2,w3=v4-v3 and so on. I'm wondering if there is any way to get value of v1,v2,v3...etc without having the value of V1?
Looking forward for your reply guys,
Thanks.
Not in general. Knowing the differences between successive numbers in a list of numbers under-determines the set of numbers. This is particularly obvious in the case when w1 = w2 = w3 = ... = wk = 1. That would tell you that the viare consecutive numbers, but nothing else could be inferred. You wouldn't be able to distinguish 3,4,5,6,7 from 10,11,12,13,14 (for example).
Having said that, it would of course be possible if you know one of the numbers, and the known number wouldn't need to be the first one. Knowing any single one of the numbers would suffice. Furthermore, knowing something like the sum of the vi would be sufficient since you could express the sum as a function of the unknown number v1 and solve the resulting equation.

Expressing set of sequences as one sequence

This is a discrete math problem, and i was hoping that someone will guide me in the right direction on how to go about solving it...
I have the following set of sequences:
a_(2n) = 8^n
This will give me the values of all the even terms
a_(2n+1) = (-3)8^n
This will give me the values of all the odd terms
I would like to know if there's a way for me to express the values of all terms (both even and odd) using only one formula! Would you please help me!
Thank you,
You can define it as follows:
a_k=[-1+2*(-1)^k]*8^(floor(k/2))

Using ifelse statement to condense variables

New to R, taking a very accelerated class with very minimal instruction. So I apologize in advance if this is a rookie question.
The assignment I have is to take a specific column that has 21 levels from a dataframe, and condense them into 4 levels, using an if, or ifelse statement. I've tried what feels like hundreds of combinations, but this is the code that seemed most promising:
> b2$LANDFORM=ifelse(b2$LANDFORM=="af","af_type",
ifelse(b2$LANDFORM=="aflb","af_type",
ifelse(b2$LANDFORM=="afub","af_type",
ifelse(b2$LANDFORD=="afwb","af_type",
ifelse(b2$LANDFORM=="afws","af_type",
ifelse(b2$LANDFORM=="bfr","bf_type",
ifelse(b2$LANDFORM=="bfrlb","bf_type",
ifelse(b2$LANDFORM=="bfrwb","bf_type",
ifelse(b2$LANDFORM=="bfrwbws","bf_type",
ifelse(b2$LANDFORM=="bfrws","bf_type",
ifelse(b2$LANDFORM=="lb","lb_type",
ifelse(bs$LANDFORM=="lbaf","lb_type",
ifelse(b2$LANDFORM=="lbub","lb_type",
ifelse(b2$LANDFORM=="lbwb","lb_type","ws_type"))))))))))))))
LANDFORM is a factor, but I tried changing it to a character too, and the code still didn't work.
"ws_type" is the catch all for the remaining variables.
the code runs without errors, but when I check it, all I get is:
> unique(b2$LANDFORM)
[1] NA "af_type"
Am I even on the right path? Any suggestions? Should I bite the bullet and make a new column with substr()? Thanks in advance.
If your new levels are just the first two letters of the old ones followed by _type you can easily achieve what you want through:
#prototype of your column
mycol<-factor(sample(c("aflb","afub","afwb","afws","bfrlb","bfrwb","bfrws","lb","lbwb","lbws","wslb","wsub"), replace=TRUE, size=100))
as.factor(paste(sep="",substr(mycol,1,2),"_type"))
After a great deal of experimenting, I consulted a co-worker, and he was able to simplify a huge amount of this. Basically, I should have made a new column composed of the first two letters of the variables in LANDFORM, and then sample from that new column and replace values in LANDFORM, in order to make the ifelse() statement much shorter. The code is:
> b2$index=as.factor(substring(b2$LANDFORM,1,2))
b2$LANDFORM=ifelse(b2$index=="af","af_type",
ifelse(b2$index=="bf","bf_type",
ifelse(b2$index=="lb","lb_type",
ifelse(b2$index=="wb","wb_type",
ifelse(b2$index=="ws","ws_type","ub_type")))))
b2$LANDFORM=as.factor(b2$LANDFORM)
Thanks to everyone who gave me some guidance!

Infopath : convert number to words .

I want to convert Info Path number Field to Word
Ex. I have no. 1000 -> Ten Thousand like that please help me.
Thank you,
As far as i know there's no built-in way to achieve this - you'll have to write custom code.
This link might help you converting numbers to text.
http://www.daniweb.com/software-development/csharp/threads/53072

Resources