LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove the last element of a string

For example, I have 0.14V, and I want 0.14.

0 Kudos
Message 1 of 7
(4,771 Views)

Browse around in the String Palate for the answer.

0 Kudos
Message 2 of 7
(4,766 Views)

Hi mshask,

 

For example, I have 0.14V, and I want 0.14.

Several options:

  1. Get the string length. Get the string subset with length-1…
  2. Reverse the string. Get the subset from offset=1. Reverse the string again…
  3. ScanFromString a float number. FormatIntoString that number…
  4. FractionalStringToNumber, followed by NumberToFractionalString…

It's a nice task to learn about all those string handling functions!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7
(4,736 Views)

Pretty simple if you use these three functions:

String to Byte Array (turns string into array)

Delete From Array (deletes last element of array by default)

Byte Array to String (array back to string)

 

Capture.PNG

0 Kudos
Message 4 of 7
(4,720 Views)

@GerdW wrote:
  1. Get the string length. Get the string subset with length-1…
  2. Reverse the string. Get the subset from offset=1. Reverse the string again…
  3. ScanFromString a float number. FormatIntoString that number…
  4. FractionalStringToNumber, followed by NumberToFractionalString…

5. Match Pattern (use ".$" as pattern, and use the before string).

6. Match Regular Expression (use ".$" as pattern, and use the before string).

7. Match Regular Expression (use "(.*).$" as pattern, extract and use the submatch 1).

8. Search and Replace String (set to Regular Expression, use ".$" as search string).

 

1. is probably the easiest answer, but you probably want a number. The first part of 3. and 4. make most sense.

 

If the pattern gets more complex, 3. and 4. become more attractive. If it gets way more complex, 5. .. 8. could be required.

0 Kudos
Message 5 of 7
(4,683 Views)

BTW:

Not exactly duplicate, but still most likely an unnecessary waste of (our) time resources:

https://forums.ni.com/t5/LabVIEW/Parse-letters-from-numbers/td-p/3936762

0 Kudos
Message 6 of 7
(4,680 Views)

wiebe@CARYA wrote:

BTW:

Not exactly duplicate, but still most likely an unnecessary waste of (our) time resources:

https://forums.ni.com/t5/LabVIEW/Parse-letters-from-numbers/td-p/3936762


Yes, both ask the wrong question (remove the extra letters instead of getting the numbers! :D) and don't really specify the desired result (still a string but with fewer characters? A numeric datatype?)

0 Kudos
Message 7 of 7
(4,654 Views)