LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to number conversion

Solved!
Go to solution

Hi,

 

This should be simple, but I can't figure out a good conversion methout "rube-goldberging" my code.

Scan from string.png

 

As I have tried to demonstrate above I am trying to get numbers from the end of a string

 

1) The string can be any length, and contain any characters.

2) There can be any amount of other numbers in the string, these are not of interest.

3) There will always be atleast one "normal" character inforont of the number I want.

 

I have a feeling the scan from string function will do what I want, but I can't figure out the right format string I should use as a input...

 

Anyone here have any good ideas? 

0 Kudos
Message 1 of 10
(5,030 Views)

Hi

 

what i have understood is, that you want the Numbers which are at the end of the string.

Is this what you want (see attached)

Somil Gautam
Think Weird
0 Kudos
Message 2 of 10
(5,024 Views)

Yes, something like that is what I want, too bad it does not work 😉

 

Your code assumes that there is always one "number character" at the end of the string with known length, but both the amount of "number characters" and the length of my string is unkown... 

0 Kudos
Message 3 of 10
(5,016 Views)
Are you sure that your string always ends with a number?
Somil Gautam
Think Weird
0 Kudos
Message 4 of 10
(5,011 Views)
string number.png
0 Kudos
Message 5 of 10
(5,006 Views)

Somil: yes, that is the just about the only safe assumption I can make...

 

Mathan: Close! But if there are numbers in the string that are not at the end, those numbers is what I get..

Message Edited by Jan_HeG on 10-28-2009 05:25 AM
0 Kudos
Message 6 of 10
(5,004 Views)
Solution
Accepted by Jan_HeG

Regular expressions are your friend:

 

Use [0-9]+$ as the regular expression. The dollar sign ($) will look for the match only if it are the last characters of the string.

 

Ton

Message Edited by TCPlomp on 28-10-2009 11:26 AM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 7 of 10
(4,999 Views)

Assuming that you have purely the digits 0-9 at the end of string, you can pre-process the strinh with "match pattern" using regular expression "[0-9]*$". This will match any number of characters chosen from the range 0 to 9 at the end of the string.

 

The match substring output is the number, so decimal string to number will then get the number into an integer.

 

Rod.

 

0 Kudos
Message 8 of 10
(4,998 Views)

thank you, i tried so much to know string to dbl.

now i got.

0 Kudos
Message 9 of 10
(4,186 Views)

can i convert dbl again to the string after inserting dbl in to an array.

0 Kudos
Message 10 of 10
(4,050 Views)