# NI TestStand

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to convert an alphanumeric string to numeric integer?

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

Message 1 of 6
(2,774 Views)
Solution
Accepted by topic author OnlyOne

## Re: How to convert an alphanumeric string to numeric integer?

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.

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,765 Views)

Great. Thank you

Message 3 of 6
(2,763 Views)

## Re: How to convert an alphanumeric string to numeric integer?

@crossrulz

Only one problem left...

How can i access the function "FindPattern"?

Message 4 of 6
(2,738 Views)

## Re: How to convert an alphanumeric string to numeric integer?

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

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 5 of 6
(2,733 Views)

## Re: How to convert an alphanumeric string to numeric integer?

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.

Message 6 of 6
(2,727 Views)