Jump to content

Replace "." with "," - replaces all numbers in to ,


Go to solution Solved by FrancescoDiMuro,

Recommended Posts

Hey guys.

I am building a manual scraper for some e-commerce numbers -> google sheet.

however since, I am a "noob" and just like to work with things, I am building this the most simple way I possible can. So everything is taken by heading to the website where it should grab the numbers, and copy it in to clipboard and then set variables according so.

Later, it will be opening google sheets and entering the data in the correct spots.

 

However, I am trying to replace . in to , with StringRegExpReplace, and it just doesnt do the trick. I am missing something.

I can easily have it exchange anything else, but as soon as I want it to exchange only the . it replaces all the numbers.

$Test = StringRegExpReplace("715.99", '.', ',')

As for example I want this to replace the text to 715,99 (seems stupid, but yea.. google sheets doesnt work with .)

 

But the value I am getting is just alot of commas.

 

What am I doing wrong? I tried putting the . in a variable to see if that helped, but it didnt change a thing.
I need help here! :)

Link to comment
Share on other sites

  • Solution
2 hours ago, ArtoAllan said:

What am I doing wrong?

The period in Regular Expressions is the meta character for "every character", so, unless you escape it with \, the function is doing its work :D
You don't really need StringRegExpReplace() to do such a simple task; just use StringReplace(), or, if you want to use SRER because you are a cat (you'll probably know in a few posts), then you should do something like this:

#include <StringConstants.au3>


Test()

Func Test()

    Local $strTest = "715.99"

    ConsoleWrite(StringRegExpReplace($strTest, '\.', ',') & @CRLF)
    ConsoleWrite(StringReplace($strTest, '.', ',') & @CRLF)

EndFunc

^_^
 

Edited by FrancescoDiMuro
StringReplace($strPostContent, "comma", "period")

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

2 minutes ago, FrancescoDiMuro said:

The comma in Regular Expressions is the meta character for "every character", so, unless you escape it with \, the function is doing its work :D
You don't really need StringRegExpReplace() to do such a simple task; just use StringReplace(), or, if you want to use SRER because you are a cat (you'll probably know in a few posts), then you should do something like this:

#include <StringConstants.au3>


Test()

Func Test()

    Local $strTest = "715.99"

    ConsoleWrite(StringRegExpReplace($strTest, '\.', ',') & @CRLF)
    ConsoleWrite(StringReplace($strTest, '.', ',') & @CRLF)

EndFunc

^_^
 

 

My man! Exactly what I was looking for!

$Test = StringRegExpReplace("715.99", '\.', ',')          ; <--- simplified

 

That does the trick, thank you soo much for a fast answer buddy! Appreciate it

Link to comment
Share on other sites

1 hour ago, FrancescoDiMuro said:

The comma in Regular Expressions is the meta character for "every character"

Tiny correction:  I think you meant the period (.) in Regular Expressions is the meta character for "any character".  :)

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...