Sign in to follow this  
Followers 0
Kappa

String

11 posts in this topic

Hey,

I have a problem to pick the strings in a file. I know that you have to use StringRegExp, but I can not figure out how. Here's an example: DOC;NO;BIG

As you can see, the constant is a string followed by two dots. Do you have any advice, please?

Kappa.

Share this post


Link to post
Share on other sites



Kappa,

Welcome to the AutoIt forum. :)

What exactly are you trying to extract from the "DOC;NO;BIG" strain? If it is "NO" then the _StringBetween function should be able to help you. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks for the welcome.

I would like to extract "DOC", "NO" and "BIG". So any string before and after the colon.

Share this post


Link to post
Share on other sites

Kappa,

If the delimiter is always ";" then you can do that very easily with StringSplit: :)

#include <Array.au3>

$sString = "DOC;NO;BIG"

$aSplit = StringSplit($sString, ";")

_ArrayDisplay($aSplit)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks, but, not knowing how many strings are there before and after the colon, I can not use that command for the way I want (or at least I think). That was an example, if you want I can find myself in this situation:

DOC;NO

or

DOC;NO;BIG;LOG

or

DOC

The most that I could do is this:

#include <Array.au3>
$String = "DOC;NO;BIG"
$Split = StringSplit($String, ";")
For $Element In $Split
   MsgBox(0, "", "Result is: " & @CRLF & $Element)
Next

But there are two problems:

1. also takes $Split[0]

2. does not include the last case (only a word without anything else)

Share this post


Link to post
Share on other sites

Not sure what you mean with item 2 but this shows the entries:

$String = "DOC;NO;BIG"
$Split = StringSplit($String, ";")
For $x = 1 to UBound($Split)-1
   ConsoleWrite($Split[$x] & @crlf) ;### Debug Console
Next

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks Jos. Adapting your example I solved it. Thanks also to Melba23!

Share this post


Link to post
Share on other sites

Try this:

#include <Array.au3>
$sText = "DOC;NO;BIG;LOG"
$aResult = StringSplitter($sText)
_ArrayDisplay($aResult)

$sText = "DOC"
$aResult = StringSplitter($sText)
_ArrayDisplay($aResult)

$sText = "DOC;NO;"
$aResult = StringSplitter($sText)
_ArrayDisplay($aResult)

Func StringSplitter($sString, $sDelimiter = ";", $bRemoveLastDelim = True)
    If $sString = "" Then Return 0
    If $bRemoveLastDelim And StringRight($sString, 1) = $sDelimiter Then $sString = StringTrimRight($sString, 1)
    Local $aTokens = StringSplit($sString, $sDelimiter, 2)
    If Not @error Then Return $aTokens
    Local $aToken[1]
    $aToken[0] = $sString
    Return $aToken
EndFunc

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks to you too, UEZ.

Share this post


Link to post
Share on other sites

I know that you have to use StringRegExp,

Indeed a Simple Example

; Splits through a SEMI-COLON (;)
#include <Array.au3>
$sInput = 'DOC;NO;BIG;'
$sOutput_Array = StringRegExp($sInput, '([^;]+)', 3)
_ArrayDisplay( $sOutput_Array )

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Nice. Very thanks.

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
Sign in to follow this  
Followers 0