Jump to content

StringRegExpReplace for multiple character


Recommended Posts

Hello

I'm obtaining date/time string into variable using _NowCalc(). String format is

YYYY/MM/DD HH:MM:SS

I'd like to replace all the "/", "<space>" and ":" with "<nothing>". How should I "show it" to StringRegExpReplace? I was trying to separate characters by brackets (like in Help) but it doesn't work

$localTime = StringRegExpReplace($localTime, "[/][ ][:]", "")

 

Edited by Ghost1982
Link to comment
Share on other sites

@Ghost1982
Use only one character class, as in the example below:

#include <StringConstants.au3>

ConsoleWrite(_RemoveDateTimeSeparators('YYYY/MM/DD HH:MM:SS') & @CRLF)

Func _RemoveDateTimeSeparators($strString)
    Return StringRegExpReplace($strString, '[ :/]', '')
EndFunc

By the way, if you want to be even verbose, you should use a different pattern:

#include <StringConstants.au3>

ConsoleWrite(_RemoveDateTimeSeparators('2020/03/04 12:10:59') & @CRLF)

Func _RemoveDateTimeSeparators($strString)
    Return StringRegExpReplace($strString, '(\d{4})/(\d{2})/(\d{2}) (\d{2}):(\d{2}):(\d{2})', '$1$2$3$4$5$6')
EndFunc

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

It is mainly a debugging tool that easily enables you to show results of operation when you run your script from Scite editor.  Although you can compile your script non-GUI (CUI) and use ConsoleWrite to send information to DOS console, it is rarely used in that perspective. 

Also you can use ConsoleWrite in Parent-Child processes where child process is sending through stream information to parent process.  This is a more frequent usage of the function.

Edited by Nine
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...