Jump to content

Split string (An easy question, i think?)


Recommended Posts

Hello!

I think this is a easy question?

The goal is to just get the date from this string.

I want to split this string:

"Open 2008-05-01 12:28 by Hans Zettberg/AVDL/RITTS"

I managed to get the "Open" in the beginning by writing:

StringTrimLeft($calldate, 5)

But the problem is that the other part dosent have a fixed chars count.

The first part is always 5 chars.

"Open "

but the last part " 12:28 by Hans Zettberg/AVDL/RITTS" can be diffrent

for exemple:

" 12:28 by Hassefels Deflindogro /ADDS/RISSST"

The best thing would be to cut the string after 10 chars. So i finally only get the date.

I'm sure that this problem have a simple solution, but i don't know it.

Thanks from Hans / Sweden

Link to comment
Share on other sites

Global $string = "Open 2008-05-01 12:28 by Hans Zettberg/AVDL/RITTS"
$re = StringRegExp($string, '[\d*-]+.*\d\d:\d\d', 3)
ConsoleWrite($re[0] & @CRLF)

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

$sString1 = 'Open 2008-05-01 12:28 by Hans Zettberg/AVDL/RITTS'

$sString2 = 'Open 2008-05-01 12:28 by Hans Zettberg/AVDL/RITTS' & @CRLF & _
            'Open 2008-05-01 12:28 by Hassefels Deflindogro /ADDS/RISSST'
; for single line.
$aStringParts = StringRegExp($sString1, '(\w*?\s\d*-\d*-\d*)|(\d*:\d*\s.*\r?)', 3)
MsgBox(266304, Default, 'First part of the string is:  ' & $aStringParts[0] & @CRLF & _
                        'Second part of the string is: ' & $aStringParts[2])
; for multi line.
$aStringParts = StringRegExp($sString2, '(\w*?\s\d*-\d*-\d*)|(\d*:\d*\s.*\r?)', 3)
MsgBox(266304, Default, 'First part of the 1st line is:  ' & $aStringParts[0] & @CRLF & _
                        'Second part of the 1st line is: ' & $aStringParts[2] & @CRLF & @CRLF & _
                        'First part of the 2nd line is: ' & $aStringParts[3] & @CRLF & _
                        'Second part of the 2nd line is: ' & $aStringParts[5])
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...