Jump to content

Recommended Posts

Posted
Example()

Func Example()
    Local $aDays = StringSplit("Mon,Tues,Wed,Thur,Fri.Sat,Sun", ",.") ; Split the string of days using the delimiter "," and the default flag value.
    For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values.
        MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i])
    Next
EndFunc   ;==>Example

Hello, this is from help file. How do i return all values excluding "Fri" which is delimited by a period?

  • Moderators
Posted

compact21,

You need a RegEx for that:

#include <Array.au3>
#include <StringConstants.au3>

$sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun"

Example()

_NoPeriod()

Func Example()
    Local $aDays = StringSplit($sText, ",.") ; Split the string of days using the delimiter "," and the default flag value.
    _ArrayDisplay($aDays, "StringSplit", Default, 8)
EndFunc   ;==>Example

Func _NoPeriod()
    $aDays = StringRegExp($sText, "(\w{3,4})(?:,|\z)", $STR_REGEXPARRAYGLOBALMATCH)
    _ArrayDisplay($aDays, "RegEx", Default, 8)
EndFunc

RegEx decode:

(\w{3,4}) - capture all sequences of 3 or 4 letters
(?:,|\z)  - followed by a comma or the end of the string, but do not capture this delimiter

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Ha, Melba and mikell beat me to it. I remove the unwanted day using StringRegExpReplace() before using StringSplit(). The regular expression is different: removing anything ending with a period. It serves as another illustration of the numerous possible ways there are to do things.
 

Example()

Func Example()
    Local $sString = StringRegExpReplace("Mon,Tues,Wed,Thur,Fri.Sat,Sun", '[^,]+\.', '') ; remove xxxx.
    Local $aDays = StringSplit($sString, ",") ; Split the string of days using the delimiter "," and the default flag value.
    For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values.
        MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i])
    Next
EndFunc   ;==>Example

 

Posted

Or if you have already determined what the string is that needs to be removed, just split on it in its entirety

#include<array.au3>

$sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun"

$aText = stringsplit($sText , "Fri." , 3)

msgbox(0, '' , _ArrayToString($aText , ""))

 

  Reveal hidden contents

Posted
  On 1/17/2016 at 4:34 PM, Melba23 said:

compact21,

You need a RegEx for that:

#include <Array.au3>
#include <StringConstants.au3>

$sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun"

Example()

_NoPeriod()

Func Example()
    Local $aDays = StringSplit($sText, ",.") ; Split the string of days using the delimiter "," and the default flag value.
    _ArrayDisplay($aDays, "StringSplit", Default, 8)
EndFunc   ;==>Example

Func _NoPeriod()
    $aDays = StringRegExp($sText, "(\w{3,4})(?:,|\z)", $STR_REGEXPARRAYGLOBALMATCH)
    _ArrayDisplay($aDays, "RegEx", Default, 8)
EndFunc

RegEx decode:

(\w{3,4}) - capture all sequences of 3 or 4 letters
(?:,|\z)  - followed by a comma or the end of the string, but do not capture this delimiter

M23

Expand  

A tip how to use StringRegExp when delimiter is "?" instead of ","   ? Thakn you.

Posted
#include<array.au3>

$delim = "?"

;~ $sText = "Mon,Tues,Wed,Thur,Fri.Sat,Sun"
$sText = "Mon,Tues,Wed?Thur,Fri,Sat,Sun"

$aText = stringsplit(stringreverse(stringregexpreplace(stringreverse($sText) , "(\" & $delim & "\D+?)," , ",")) , "," , 2)

_ArrayDisplay($aText)

 

  Reveal hidden contents

Posted (edited)

yup I was backwards, I totally thought he asked what if it was '?' instead of '.' 

\Q....\E would make my regex life so much easier if I remembered to use them, but working on the reversed string is still my favorite way to provide examples :)

Edited by iamtheky

  Reveal hidden contents

Posted

but its an easy win for the recipient to fix and then they have to reverse the regex which means they did something more than copy/paste.  And if you see that crap from anyone but me, you know where they got it from.

  Reveal hidden contents

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