String length and substrings

Hi. I’m wondering if there’s a way to have CL find the length of a string, and also reference a substring. For example, if the input is 10011, I want to know that the 3rd character is 0, and also that the string has 5 characters. Thanks!

1 Like

There aren’t really any string methods. If you’re actually doing something with numbers, there are ways to achieve the same objective. Not sure about length, but
this finds the 3rd place value.

v = 10011
p3 = numericValue("\floor( \mod(${v},1000) /100 ) ") 

Thanks, that’s really helpful. I’m not starting with a long number, just the digits. I’m struggling with doing simple computations (a+b) in the CL, but I think I see now. I need to use ${a} to have it be a value. Thanks again.

I realize I forgot the \ before each of the operators, floor and mod. I edited the other post. You could also use a function to generalize for different place values.

p = simpleFunction("\floor(\mod(v),10^p)/ (10^(p-1))" , "v" ,"p")

Then, to use it:

place3 = p.evaluateAt(v1,3)
place1 = p.evaluateAt(v1,1)

First: Thanks so much for your help! Second: That’s really funny, because I spent a long time trying to use the mod function and it was driving me crazy that it wouldn’t work. Then I looked back and said, “Ohhhh - backslash!” palm to forehead. I guess you had edited it in between. And third: Thanks again! I’m making slow progress but I’m learning a lot!

1 Like

I would like to be able to identify the length of a string. There was nothing available 2 years ago but perhaps there have been updates since then?