Cropping the last two chars of a string of varying length

advanced-prototyping

#1

Can any of you good folk tell me how I go about cutting/trimming/ cropping the last two chars of a given string of varying length?

eg:

  1. 1790 > 17
  2. 87094 > 870
  3. 675674 > 6756

#2

Use the slice command in the set text action:
[[LVAR1.slice(0,-2)]]

Where LVAR1 is the text on the widget you want to remove the last two characters…

See attached sample - i’m setting it on text change of the text field, but you can do the same thing any other place.

remove Last Two Characters.rp (45.4 KB)


#3

Thank you for the swift response, if you don’t mind I have one more. How would I translate these?

500 > 0.5
50 > 0.05
1500 > 1.5

(g > kg)


#4

Hi,

1kg = 1000g,
so divide your first value by 1000:
image

(500 will become 500/1000=0.5 ;
50 => 50/1000=0.05 ;
…)

Best


#5

That’s a lot more straightforward than I thought it would be, thank you both.

Apologies for the noob questions


closed #6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.