IronFine Posted April 11 Posted April 11 (edited) Hi everyone, I'm currently working on a project that involves heavy string manipulation, where I am working with large datasets. There I need to match specific patterns, modify the matches, and then replace the changes back into the string. I am already mixed the use of StringReplace and StringRegExpReplace, depending where either one is fater (determined that for most of the cases once). Also I am using the case-sensitivity flag/replace count where possible. I tried to also use CLR and calling a C# hoping that that would be faster, but with the overhead it is only faster in some cases. Are there any other tipps that I can use? Edited April 11 by IronFine
Nine Posted April 11 Posted April 11 There is not much you can do using standard String* functions. Most of them (when modifying the original string) makes a copy of the string. With small strings, it is not a big deal. But when it comes to large strings, it can be quite lengthy to execute multiple string operations over a single string. One method would be to perform in place replacements. That is quite easy if you replace N characters with some other N characters. Also it depends where the strings are coming from and where they go (text files ?). Do they have known formats they are following (like json or xml) ? Best way to help you, would be for you to provide a real life example, so we can try to look into a solution tailored to your situation. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
jchd Posted April 12 Posted April 12 (edited) What @Nine said, but beware of this: 13 hours ago, Nine said: That is quite easy if you replace N characters with some other N characters. Not that easy. Windows uses UTF16-LE internally, which means that a "character" (here I mean actually "one Unicode codepoint") can use either one or two 16-bit words. in RAM. Also, don't forget that AutoIt uses a subset of UTF16-LE named UCS-2, allowing full use of the Unicode BMP (Basic Multilingual Plane), i.e. codepoints U+0000 to U+FFFF. Hence, counting "characters" is not trivial. Common "characters" in non-english languages like à, Ê, ù, ç, ñ, ... can be represented using different normalization forms, see https://en.wikipedia.org/wiki/Unicode_equivalence#Normalization Moretheless what we, humans, mean by "character" may require more than one Unicode codepoint. This is the difference between glyph (what is displayed by the font renderer) and codepoint (the actual Unicode content). For instance this string $s = ChrW(0xD83D) & ChrW(0xDC68) & ChrW(0xD83C) & ChrW(0xDFFB) & ChrW(0x200D) & ChrW(0xD83D) & ChrW(0xDC69) & ChrW(0xD83C) & ChrW(0xDFFF) & ChrW(0x200D) & ChrW(0xD83D) & ChrW(0xDC66) & ChrW(0xD83C) & ChrW(0xDFFD) displays as in a Unicode-aware environment. And that is only speaking of valid representations: one may find out-of-spec representations in input strings, spanning representation of what we perceive as a "character" over an unbounded string of Unicode codepoints. Edited April 12 by jchd Gianni, Danyfirex and pixelsearch 3 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
IronFine Posted April 19 Author Posted April 19 Thank you both for your reply. @Nine my script is processing text-files/source code with nested expressions. Each expression is replaced with a token, operating from top to bottom. Once everything is tokenized, the string for the nested expression is manipulated. Once all that is done, all the token will be replaced with the new/manipulated string - bottom to top.
Nine Posted April 19 Posted April 19 Again, without a real example from your text files, not much we can recommend to help you. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
junkew Posted April 23 Posted April 23 you could quickly split it into single (unicode) chars with stringsplit and then iterate each character basically build your own tokenizer. Not neccesarily fast in AutoIt Local $sText = "Winter"& ChrW(9731) & "Snow" & ChrW(9731) & "Ice" ; Split in single (unicode)characters Local $aResult = StringSplit($sText, "") local $foundStr="" For $i = 1 To $aResult[0] $char=$aResult[$i] if ($char=chrw(9731)) Then _ConsoleWrite($foundStr & " rain" & @CRLF) $foundStr="" Else $foundStr&=$char endif Next _ConsoleWrite($foundStr & " rain" & @CRLF) Func _ConsoleWrite($sString) Local $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _ "ptr", 0, "int", 0, "ptr", 0, "ptr", 0) If @error Then Return SetError(1, @error, 0) Local $tText = DllStructCreate("char[" & $aResult[0] & "]") $aResult = DllCall("Kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _ "ptr", DllStructGetPtr($tText), "int", $aResult[0], "ptr", 0, "ptr", 0) If @error Then Return SetError(2, @error, 0) ConsoleWrite(DllStructGetData($tText, 1)) EndFunc FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now