Jump to content

[CLOSED] _StringRegExpMultiReplace


FireFox
 Share

Recommended Posts

Hi,

I saw this exemple for MultiReplace of StringRegExpReplace

_StringRegExpMultiReplace($sString, $aPattern, $aReplace)

So i want to use with this :

$replace=_StringRegExpMultiReplace("C:\|0//D:\|1//E:\|2", "//D:\|1", "")
   Msgbox(0,"",$replace)
   
   Func _StringRegExpMultiReplace($sString, $aPattern, $aReplace)
       If Not IsArray($aPattern) Or Not IsArray($aReplace) Then Return SetError(1, 0, $sString)
   
       Local $iExtended = 0
       ReDim $aReplace[UBound($aPattern)]
   
       For $i = 0 To UBound($aPattern) - 1
           $sString = StringRegExpReplace($sString, $aPattern[$i], $aReplace[$i])
           $iExtended += @extended
       Next
   
       Return SetError(0, $iExtended, $sString)
   EndFunc;==>_StringRegExpMultiReplace

I want to replace //D:\|1 by "" (its an example)

Thanks for anyhelp :)

Edited by FireFox
Link to comment
Share on other sites

Parameters 2 and 3 have to be an array.

Hum you mean variables ?

$aPattern = "//D:\|1"
 $aReplace = ""
 $replace = _StringRegExpMultiReplace("C:\|0//D:\|1//E:\|2", $aPattern, $aReplace)
 MsgBox(0,"",$replace)
 
 Func _StringRegExpMultiReplace($sString, $aPattern, $aReplace)
     If Not IsArray($aPattern) Or Not IsArray($aReplace) Then Return SetError(1, 0, $sString)
 
     Local $iExtended = 0
     ReDim $aReplace[UBound($aPattern)]
 
     For $i = 0 To UBound($aPattern) - 1
         $sString = StringRegExpReplace($sString, $aPattern[$i], $aReplace[$i])
         $iExtended += @extended
     Next
 
     Return SetError(0, $iExtended, $sString)
 EndFunc ;==>_StringRegExpMultiReplace

Still doesnt work if you meant that :)

Edited by FireFox
Link to comment
Share on other sites

  • Moderators

Hum you mean variables ?

$aPattern = "//D:\|1"
 $aReplace = ""
 $replace = _StringRegExpMultiReplace("C:\|0//D:\|1//E:\|2", $aPattern, $aReplace)
 MsgBox(0,"",$replace)
 
 Func _StringRegExpMultiReplace($sString, $aPattern, $aReplace)
     If Not IsArray($aPattern) Or Not IsArray($aReplace) Then Return SetError(1, 0, $sString)
 
     Local $iExtended = 0
     ReDim $aReplace[UBound($aPattern)]
 
     For $i = 0 To UBound($aPattern) - 1
         $sString = StringRegExpReplace($sString, $aPattern[$i], $aReplace[$i])
         $iExtended += @extended
     Next
 
     Return SetError(0, $iExtended, $sString)
 EndFunc;==>_StringRegExpMultiReplace

Still doesnt work if you meant that :)

No, I mean Array.

http://www.autoitscript.com/wiki/Arrays

Edit:

And the 2nd parameter is an array of the Regular Expressions you are going to use for each replacement array (which is the 3rd parameter)....

This function looks like something Geosoft would write.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

No, I mean Array.

http://www.autoitscript.com/wiki/Arrays

Edit:

And the 2nd parameter is an array of the Regular Expressions you are going to use for each replacement array (which is the 3rd parameter)....

This function looks like something Geosoft would write.

@SmOke_N

Sorry to ask question to you again,

I read array wiki you gave me, but i dont realize how to use it with function :)

Link to comment
Share on other sites

@SmOke_N

Sorry to ask question to you again,

I read array wiki you gave me, but i dont realize how to use it with function :)

If you look at the example that MrCreator made he would have passed arrays as parameters like SmOke_N said.

Also, your search contains the "|" charcter and you'll need to escape that.

Dim $pattern[1] = ["//D:\\|1"]
Dim $Replace[1] = [""]
$replace=_StringRegExpMultiReplace("C:\|0//D:\|1//E:\|2",$pattern, $replace)
   Msgbox(0,"",$replace)
  
   Func _StringRegExpMultiReplace($sString, $aPattern, $aReplace)
       If Not IsArray($aPattern) Or Not IsArray($aReplace) Then Return SetError(1, 0, $sString)
  
       Local $iExtended = 0
       ReDim $aReplace[UBound($aPattern)]
  
       For $i = 0 To UBound($aPattern) - 1
           $sString = StringRegExpReplace($sString, $aPattern[$i], $aReplace[$i])
           $iExtended += @extended
       Next
  
       Return SetError(0, $iExtended, $sString)
   EndFunc;==>_StringRegExpMultiReplace

Obviously if you only have one patern and one replace then the function serves no purpose, but I know this is just an example.

EDIT: spelling

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Nothing is needed here other than 1 line of code... Not sure why you are using this, other than the fact that you felt you didn't need to know RegEx or know how to use Arrays (Neither of which are true).

StringReplace would do the same for you without the need of RegEx knowledge or Array Knowledge.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Nothing is needed here other than 1 line of code... Not sure why you are using this, other than the fact that you felt you didn't need to know RegEx or know how to use Arrays (Neither of which are true).

StringReplace would do the same for you without the need of RegEx knowledge or Array Knowledge.

Thanks for your answers, I've tried this functions because I've already asked my problem.

I just want to search characters/sentence and delete it from file :)

Link to comment
Share on other sites

This function looks like something Geosoft would write.

Or me :) (modified by amel27).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

This function looks like something Geosoft would write.

I resemble that remark.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

Ok...Anyhelp ?

You've said this to others, so I'll say it to you... Don't bump within 24 hours of your last post... In addition, don't start multiple topics on the same subject... If this question was specifically on the function, then you should have posted your question in that thread.... And it's obviously not about this function, because Martin showed you how to use it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You've said this to others, so I'll say it to you... Don't bump within 24 hours of your last post... In addition, don't start multiple topics on the same subject... If this question was specifically on the function, then you should have posted your question in that thread.... And it's obviously not about this function, because Martin showed you how to use it.

Ok, i bumped because other members weren't speaking about my function so I just Mr creator to give little help but if the func isn't for do it I resolved my problem and bump my other topic about general string split :)
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...