JamesBiggles Posted October 29, 2013 Share Posted October 29, 2013 (edited) Disclaimer: I've never coded and I just started AutoIt yesterday. Total newb alert. I need to do a very, very simple task in a text file, but apparently some necessary syntax is eluding me. I need to take this bit of text: SQUAD, NAME_RIFLE_formation), And turn it into this: SQUAD,NAME_RIFLE_formation), Essentially I need to remove the carriage return and tab between the "SQUAD," and "NAME_RIFLE_formation)," strings. EDIT to add: This text is part of a larger file (a simple text document). I can't just remove all carriage returns, I can only very specifically remove the carriage returns between these two strings of text. I've tried StringStripCR: Local $result = StringStripCR("SQUAD," & Chr(13) & Chr(10) & Chr(9) & "NAME_RIFLE_formation),") I also tried StringStripWS. When I run either, nothing happens. I think I'm messing up some syntax or something. What am I doing wrong? Edited October 29, 2013 by JamesBiggles Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 29, 2013 Moderators Share Posted October 29, 2013 JamesBiggles,Welcome to the AutoIt forum. Is this text part of a larger file? I ask because the task of removing the @CRLF in that case is significantly different to simple case of it being a stand-alone string as in your OP. M23P.S. Any relation to this well-known James Bigglesworth? 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JamesBiggles Posted October 29, 2013 Author Share Posted October 29, 2013 (edited) JamesBiggles, Welcome to the AutoIt forum. Thank you! Is this text part of a larger file? I ask because the task of removing the @CRLF in that case is significantly different to simple case of it being a stand-alone string as in your OP. Ah yes, should have mentioned that. This text is part of a larger file (a simple text document). I can't just remove all carriage returns, I can only very specifically remove the carriage returns between these two strings of text. P.S. Any relation to this well-known James Bigglesworth? I wish! Edited October 29, 2013 by JamesBiggles Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 29, 2013 Share Posted October 29, 2013 (edited) Then you need to define the rules. Strip CR when line doesn't end with a ), ? Edited October 29, 2013 by Xenobiologist 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 More sharing options...
Moderators Melba23 Posted October 29, 2013 Moderators Share Posted October 29, 2013 (edited) JamesBiggles,I would use a RegEx to do this:$sText = "Blah blah" & @CRLF & _ "SQUAD," & @CRLF & _ "NAME_RIFLE_formation)," & @CRLF & _ "blah blah" $sNewText = StringRegExpReplace($sText, "(?is)^(.*squad,).*(name_rifle.*)$", "$1$2") ConsoleWrite($sNewText & @CRLF)To explain:(?is) - Make everything case-insensitive and treat line breaks as normal characters ^ - Start at the beginning and (.*squad,) - capture everything up to the word "squad" .* - Ignore anything until (name_rifle.*) - we capture everything from "name_rifle" onwards to $ - the end $i$2 - Replace everything above by the 2 groups we capturedMakes the head spin - but it is the best way to do this! Please ask if you have any questions. M23 Edited October 29, 2013 by Melba23 Typo 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JamesBiggles Posted October 29, 2013 Author Share Posted October 29, 2013 JamesBiggles, I would use a RegEx to do this: $sText = "Blah blah" & @CRLF & _ "SQUAD," & @CRLF & _ "NAME_RIFLE_formation)," & @CRLF & _ "blah blah" $sNewText = StringRegExpReplace($sText, "(?is)^(.*squad,).*(name_rifle.*)$", "$1$2") ConsoleWrite($sNewText & @CRLF) Please ask if you have any questions. What are the "Blah blah"s I see in the $sText? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 29, 2013 Moderators Share Posted October 29, 2013 JamesBiggles,They represent the additional text you said you had in the file. Just replace the beginning of the code with this and run the script on your actual file:$sText = FileRead("Your_Filename")Now you have the real file content in the $sText variable and you can see if it works "in the wild". If it does not then I suggets you post a copy of the file (perhaps suitably redacted) here so we can see what is going on. M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 31, 2013 Moderators Share Posted October 31, 2013 JamesBiggles,That is a significantly different problem to the one you initially suggested. In future, please give us the full requirement from the beginning as having the goal posts moved mid-thread is extremely annoying. It usually means that the assistance given previously is not adapted to the particular case and so a complete waste of time for those who bothered to answer - and who might not bother to continue. Point taken I hope. It is not difficult to read in that basic file and modify it as you require. It is worth noticing that the file contains 2 forms of EOL (@CR and @CRLF) so that might well have led to your difficulties. Here is my take on how you might do it:expandcollapse popup#include <Constants.au3> ; Read generic file $sGeneric = FileRead("SquadData_GENERIC.h") ; 0d and 0d0a EOL!!!! ; Replace all EOL with , $sStandard = StringRegExpReplace($sGeneric, "((?<!\x0d)\x0a|\x0d(?!\x0a)|\x0d\x0a)", ",") ; Strip " $sStripped = StringReplace($sStandard, '"', '') ; Split into elements $aElements = StringSplit($sStripped, ",") ; Declare variable to hold final result $sFinal = "(" & @CRLF ; Now loop through elements and create the new string For $i = 1 To $aElements[0] ; Read element $sElement = $aElements[$i] ; Act depending on content Switch $sElement Case "SQUAD" ; Add brackets and remove internal blanks $sFinal &= @TAB & $sElement & "(" & $aElements[$i + 1] & "_formation)," & @CRLF $i += 1 Case Else ; If it begins "TEAM_" If StringLeft($sElement, 5) = "TEAM_" Then ; Add internal and closing and opening braces $sFinal &= @TAB & "{" & $sElement & "," & @CRLF & @TAB & $aElements[$i + 6] & "}," & @CRLF & "}" & @CRLF & "{" & @CRLF ; Skip to next section element $i += 6 Else ; Add element $sFinal &= @TAB & $sElement & "," & @CRLF EndIf EndSwitch Next ; Remove the excess opening brace $sFinal = StringTrimRight($sFinal, 8) ; And here is what we get MsgBox($MB_SYSTEMMODAL, "Final", $sFinal)Does that fit the bill? M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JamesBiggles Posted October 31, 2013 Author Share Posted October 31, 2013 I've found a solution. Thanks for your time and patience. Link to comment Share on other sites More sharing options...
ovaron Posted December 2, 2014 Share Posted December 2, 2014 Late ok, much later, but also a quick option to remove the control characters. Simply do it twice with Stringreplace() -> one time for each control character... #include <String.au3> $sText = "Blah blah" & @CRLF & _ "SQUAD," & @CRLF & _ "NAME_RIFLE_formation)," & @CRLF & _ "blah blah" $sText = StringReplace($sText, @CR, "") ;CR out $sText = StringReplace($sText, @LF, "") ;LF out ConsoleWrite($sText & @CRLF) Regards, Tombac ss26 1 Link to comment Share on other sites More sharing options...
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