10-05-2021 06:50 AM
Hello,
how can i convert a alphanumeric string like abc00000123 to a numeric integer value 123?
The characters are only leading characters and the number is at the end.
So the only thing is on how to remove the leading not-numeric characters.
The leading characters have not a fix length.
Thanks
Solved! Go to Solution.
10-05-2021 07:36 AM
Try this. I used Locals.str for the string input.
Locals.num = Val(Right(Locals.str,Len(Locals.str) - FindPattern(Locals.str,"[0-9]")))
FindPattern() looks for a regular expression in the string. So I did a search for a numeric character.
Len() returns the length of the string.
Right() returns the last X characters in a string.
Val() converts a string into a numeric.
So Len() - FindPattern gives me the number of numeric characters at the end of the string. Right() then gets the numeric characters. And finally Val() converts the numeric characters into a numeric data type.
10-05-2021 07:42 AM
Great. Thank you
10-05-2021 09:27 AM
@crossrulz
Only one problem left...
How can i access the function "FindPattern"?
10-05-2021 10:03 AM
@OnlyOne wrote:
@crossrulz
Only one problem left...
How can i access the function "FindPattern"?
Looks like that function was added in TestStand 2020 (https://forums.ni.com/t5/NI-TestStand-Idea-Exchange/Add-Regular-Expression-comparison-type-to-String...). That thread also shows a way to do it with a .NET adapter. Alternatively, you could make a LabVIEW VI to do this whole thing for you.
10-05-2021 10:12 AM
Ah, i am using TS 2019.
Meanwhile i solved it by manually looping through the string and checking each character if its a number.
Then i can use your statement.