Sign in to follow this  
Followers 0
Ultima2

How to extract float number from a string?

13 posts in this topic

#1 ·  Posted (edited)

$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

Share this post


Link to post
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

........


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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 :)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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)

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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)

Share this post


Link to post
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).

Share this post


Link to post
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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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).

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

$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

Share this post


Link to post
Share on other sites

$x = 3.14

$z = 2.6243563

$ok = $x & "," & $z

$ss = StringSplit($ok, ",")

; $ss is [2, "3.14", "2.6243563"]

$newx = Number($ss[1])

$newy = Number($ss[2])

Share this post


Link to post
Share on other sites

Thank you. I'll try to read the help file again. The help file is like written in another language, I only understand like 2% of it

Share this post


Link to post
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
Sign in to follow this  
Followers 0