RyeStick Posted June 19, 2021 Share Posted June 19, 2021 Hello, Would someone be able to help me with something. I have a number say 1,62918 which has a comma but I need it as 1.62918 with a point, how do I go about doing this? Link to comment Share on other sites More sharing options...
RyeStick Posted June 19, 2021 Author Share Posted June 19, 2021 Nevermind I sussed it. I used StringReplace() Local $sString = StringReplace("1,62918.", ",", ".") Local $iReplacements = @extended MsgBox($MB_SYSTEMMODAL, "", $iReplacements & " replacements were made and the new string is:" & @CRLF & @CRLF & $sString) I did spend about an hour prior to posting this trying to figure this out. Sorry for wasting your time. Link to comment Share on other sites More sharing options...
Solution Malkey Posted June 20, 2021 Solution Share Posted June 20, 2021 Using StringReplace() is fine to blanket convert all commas. In case there are any commas in the string that don't need converting, here is a conditional converting method. Local $sOrigString = 'When a comma is between digits, replace with a point e.g. StringReplace("1,62918,", ",", ".")' Local $sString = StringRegExpReplace($sOrigString, "(?<=\d),(?=\d)", ".") Local $iReplacements = @extended MsgBox(4096, "", $iReplacements & " replacement" & _ ; $MB_SYSTEMMODAL is 4096 ($iReplacements = 1 ? " was" : "s were") & _ ; Allow for plural or singular grammatically. " made and the new string is:" & _ @CRLF & @CRLF & $sString) ; The RE Pattern:- ; "(?<=\d)," - (Lookbehind assertions) Match an occurrence of a comma, ",", that is preceded by a digit, "\d", but does not include the digit in the match; and, ; ",(?=\d)" - (Lookahead assertions) Matches a comma followed by a digit, "\d", but does not include the digit in the match. ; So, to match a particular comma to convert, there must be a digit on either side of the comma. ; Returns :- ; 1 replacement was made and the new string is: ; ; When a comma is between digits, replace with a point e.g. StringReplace("1.62918,", ",", ".") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ : Replacement : Comma converted to point. RyeStick, Musashi and robertocm 2 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now