Jump to content

How to extract float number from a string?


Ultima2
 Share

Recommended Posts

$number = 2.3
$number1 = 1.5
$ok = ""&$number&", "&$number1&"j"

How do I extract $number and $number1 from the string and set them separately to float point numbers again?

I tried the help file but couldnt find anything that could help me

Edited by Ultima2
Link to comment
Share on other sites

$number = 2.3
$number1 = 1.5
$ok = ""&$number&", "&$number1&"j"

How do I extract $number and $number1 from the string and set it to a float point number again?

I tried the help file but couldnt find anything that could help me

Hi,

For extract it you can use string functions :

StringSplit

StringLeft

StringRight

StringTrimLeft

StringTrimRight

StringReplace

........

Link to comment
Share on other sites

Could you post an example please, that doesn't really help me because im still a newbie D:

$String="Number 1.5 and Number 2"
$Number1=StringLeft(StringTrimLeft($String,7),3)
$Number2=StringRight($String,1)
Msgbox(64,"",$Number1&" and "&$Number2)

You can check this functions on autoit helpfile with F1 key in SciTE :)

Link to comment
Share on other sites

Ok thank you very much, but what if you dont know the exact digit of the number, like log(3).

Like

$x = log(3)
$z = log(2)
$ok = ""&$x&", "&$z&""

How would you extract the entire value of $x and $z from the string? Thanks :)

Edited by Ultima2
Link to comment
Share on other sites

Ok thank you very much, but what if you dont know the exact digit of the number, like log(3).

Like

$x = log(3)
$z = log(2)
$ok = ""&$x&", "&$z&""

How would you extract the entire value of $x and $z from the string? Thanks :)

Do you want to search all numbers in a log ? (1-9)
Link to comment
Share on other sites

Try this :)

#include <Array.au3>

$x = log(3)
$z = log(2)
$ok = ""&$x&", "&$z&""

;~ $number = 2.3
;~ $number1 = 1.5
;~ $ok = ""&$number&", "&$number1&"j"

ConsoleWrite($ok)


$new = StringRegExpReplace($ok,"[^0-9.\s]","")
$array = StringSplit($new, " ")
_ArrayDisplay($array)
Link to comment
Share on other sites

No I just want to know how to extract a number from a string. How do I extract a number from a string if I dont know the exact length of the number. like sqrt(5).

if you don't length of the number you have to search it... look at StringRegExp , Stringinstr
Link to comment
Share on other sites

I cant understand the help file. They're like written for people with 180+ IQ. Like for the code

$x = log(3)
$z = log(2)
$ok = ""&$x&", "&$z&""

I have a string "$x, $z". How do I extract $x and $z from the string. I cant use the method you showed me earlier because it only works if I know the exact length of log(3) and log(2).

Link to comment
Share on other sites

$number = 2.3
$number1 = 1.5
$ok = ""&$number&", "&$number1&"j"

ConsoleWrite($ok & @CR)

$new = StringRegExpReplace($ok,"[^0-9.\s]","")
$array = StringSplit($new, " ")
ConsoleWrite($array[1] & " " & $array[2] & @CR)

$x = log(3)
$z = log(2)
$ok = ""&$x&", "&$z&""

ConsoleWrite($ok & @CR)

$new = StringRegExpReplace($ok,"[^0-9.\s]","")
$array = StringSplit($new, " ")
ConsoleWrite("x=" & $array[1] & " z=" & $array[2] & @CR)

If this isn't what you asked for please explain how you mean.

Edited by Pain
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...