Jump to content

replace value


Go to solution Solved by Merchants,

Recommended Posts

i want to replace smaller numbers into large number and i can't do it with one string replace or i need to stack it up but that is not so economic

so i need a better func for it

;input = test 2
StringReplace(StringReplace("test 2", "2","1"), " ","-") ;Output = test-1

when i create a input text i want to put it in a generator so that i get a output that i want some examples below:

input = "5k" -> i want to see a output of: 5000

and some more examples:

5k -> 5000

1k -> 1000

2,2k -> 2200

1m -> 1000000

and i also like to convert it backwords

5000 -> 5k

1000 -> 1k

2200 -> 2,2k

etc...

Link to comment
Share on other sites

  • Solution

Found it my self:

 

$number="100k"
Msgbox(64,"input", "input: " & $number)
If StringRegExp($number,"k") Then
    $R = StringReplace(StringReplace(StringReplace($number, ",","."), " ",""), "k","")*1000
ElseIf StringRegExp($number,"m") Then
    $R = StringReplace(StringReplace(StringReplace($number, ",","."), " ",""), "m","")*1000000
Else
    $R = StringReplace($number, ",",".")
EndIf
Msgbox(64,"output", "output: " & $R)
; -> From small to large numbers


$number="100000"
Msgbox(64,"input", "input: " & $number)
If ($number > 9999 And $number < 999999) Then
    $R = $number/1000 & "k"
ElseIf $number > 999999 Then
    $R = $number/1000000 & "m"
Else
    $R = $number
EndIf
Msgbox(64,"output", "output: " & $R)
; -> From large to smaller numbers
Edited by Merchants
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...