Jump to content
Ghost1982

StringRegExpReplace for multiple character

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)

@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

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)

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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...