NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert an alphanumeric string to numeric integer?

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(2,787 Views)
Solution
Accepted by topic author OnlyOne

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(2,778 Views)

Great. Thank you

0 Kudos
Message 3 of 6
(2,776 Views)

@crossrulz

Only one problem left...

How can i access the function "FindPattern"?

 

0 Kudos
Message 4 of 6
(2,751 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(2,746 Views)

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.

0 Kudos
Message 6 of 6
(2,740 Views)