RestrictedUser Posted March 21, 2019 Share Posted March 21, 2019 (edited) Hello AutoIt Scriptwriters! 👋❤️ I have some questions about text extracting from file then save extracted texts to new text file Q1) How to extract texts after ":" delimiter in text file? For example: New1:Old4 New28:Old3 New21:Old2 And i want to output be this: Old4 Old3 Old2 ================================= Q2) How to extract Proxies with their Ports in each line of text file? For example: helloHelloBye192.168.1.1:123418292293hdhfhdbdabgsgs And i want to output be this; 192.168.1.1:12341 The largest and valid Port number in the world is 65535 ================================= Q3) How to extract duplicate texts with case sensitive after ":" delimiter? For example: Bugs:Hello Bugs:Hello Bugs:hello And i want to output be this; Hello Edited March 22, 2019 by Colduction Link to comment Share on other sites More sharing options...
BrewManNH Posted March 22, 2019 Share Posted March 22, 2019 Look at StringSplit in the help file for questions 1 and 3, and for 3 look at _ArrayUnique after the stringsplit. RestrictedUser 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
iAmNewbe Posted March 22, 2019 Share Posted March 22, 2019 #include <String.au3> #include <Array.au3> #include <MsgBoxConstants.au3> $string = "helloHelloBye192.168.1.1:123418292293hdhfhdbdabgsgs" $arraySplitString = StringSplit(StringRegExpReplace($string, '([^0-9.:])', ''), ':') $result = $arraySplitString[1] & ":" & StringLeft($arraySplitString[2], 5) MsgBox(0,"", $result) This takes care of #2 RestrictedUser 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 22, 2019 Share Posted March 22, 2019 @Colduction The question is always the same... What did you try so far? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Nine Posted March 22, 2019 Share Posted March 22, 2019 Well for Q2, how do you know the port is 12341 and not 1234 or 123 or 12 or simply 1 ? “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 23, 2019 Author Share Posted March 23, 2019 On 3/22/2019 at 5:37 AM, BrewManNH said: look at _ArrayUnique Hmmm, thanks bro I have to watch and learn examples from help file to understand It's difficult to understand, but i can😓😅 Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 23, 2019 Author Share Posted March 23, 2019 On 3/22/2019 at 9:02 AM, iAmNewbe said: #include <String.au3> #include <Array.au3> #include <MsgBoxConstants.au3> $string = "helloHelloBye192.168.1.1:123418292293hdhfhdbdabgsgs" $arraySplitString = StringSplit(StringRegExpReplace($string, '([^0-9.:])', ''), ':') $result = $arraySplitString[1] & ":" & StringLeft($arraySplitString[2], 5) MsgBox(0,"", $result) This takes care of #2 Thanks for helping me👍❤️ Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 23, 2019 Author Share Posted March 23, 2019 20 hours ago, FrancescoDiMuro said: @Colduction The question is always the same... What did you try so far? Which one? I've tried many times, but it's difficult for newbie as i😅 Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 23, 2019 Author Share Posted March 23, 2019 18 hours ago, Nine said: Well for Q2, how do you know the port is 12341 and not 1234 or 123 or 12 or simply 1 ? I gave hard example to get and detect maximum port of ip address Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 23, 2019 Share Posted March 23, 2019 1 hour ago, Colduction said: I've tried many times Show us then. Maximum port is and will always be 65535, but how do you know, in those five numbers after the IP address, where the port number finishes? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 23, 2019 Author Share Posted March 23, 2019 16 hours ago, FrancescoDiMuro said: Show us then. Maximum port is and will always be 65535, but how do you know, in those five numbers after the IP address, where the port number finishes? 17 hours ago, Colduction said: I gave hard example to get and detect maximum port of ip address Link to comment Share on other sites More sharing options...
Malkey Posted March 24, 2019 Share Posted March 24, 2019 Here are some example answers to the three questions of post #1. expandcollapse popupConsoleWrite(" ---- Ans 1 ------" & @CRLF) $sStr1 = "New1:Old4" & @CRLF & "New28:Old3" & @CRLF & "New21:Old2" ; or, $sStr1 = FileRead($sFileName) $sStr1New = StringRegExpReplace($sStr1, '(.+:)', '') ConsoleWrite($sStr1New & @CRLF) ; or ConsoleWrite(" ---- Ans 1a ------" & @CRLF) $sStr1NewA = "" StringReplace($sStr1, ":", "") $iCount = @extended For $i = 1 To $iCount $sStr1NewA &= StringMid($sStr1, StringInStr($sStr1, ":", 0, $i) + 1, StringInStr($sStr1, @CR, 0, $i) - StringInStr($sStr1, ":", 0, $i)) Next ConsoleWrite($sStr1NewA & @CRLF) ;#cs ; -------------------- Write to file ----------------- Local $sFileName = "TestFile1.txt" If FileExists($sFileName) Then FileDelete($sFileName) FileWrite($sFileName, StringRegExpReplace($sStr1, '(.+:)', '')) Do Until FileExists($sFileName) ShellExecute($sFileName) ;#ce ConsoleWrite(" ---- Ans 2a ------" & @CRLF) $sStr2a = "helloHelloBye192.168.1.1:023418292293hdhfhdbdabgsgs" $REPattern = '^\D+([\d.]+):(\d{0,6}).*$' $REReplacement = '"\1:"&(\2<=65535?"\2":(StringTrimRight("\2",1)<=65535?StringTrimRight("\2",1):StringTrimRight("\2",2)))' $sStr2Newa = StringRegExpReplace($sStr2a, $REPattern, $REReplacement) ;ConsoleWrite($sStr2Newa & @CRLF) ConsoleWrite(Execute($sStr2Newa) & @CRLF) ConsoleWrite(" ---- Ans 2b ------" & @CRLF) Local $sStr2b = "helloHelloBye192.168.1.1:123418292293hdhfhdbdabgsgs" Local $sStr2Newb = StringRegExpReplace($sStr2b, $REPattern, $REReplacement) ;ConsoleWrite($sStr2Newb & @CRLF) ConsoleWrite(Execute($sStr2Newb) & @CRLF) ConsoleWrite(" ---- Ans 2c ------" & @CRLF) $sStr2c = "helloHelloBye192.168.1.1:723418292293hdhfhdbdabgsgs" $sStr2Newc = StringRegExpReplace($sStr2c, $REPattern, $REReplacement) ;ConsoleWrite($sStr2Newc & @CRLF) ConsoleWrite(Execute($sStr2Newc) & @CRLF) ConsoleWrite(" ---- Ans 3 ------" & @CRLF) $sStr3 = "Bugs:Hello" & @CRLF & "Bugs:Hello" & @CRLF & "Bugs:Hello" ConsoleWrite(StringRegExpReplace(StringRegExpReplace($sStr3, '((.+)\R?)+', '\1'), '(.+:)', '') & @CRLF) RestrictedUser 1 Link to comment Share on other sites More sharing options...
RestrictedUser Posted March 24, 2019 Author Share Posted March 24, 2019 5 hours ago, Malkey said: example answers to the three questions of post #1. Thanks bro, it's very useful for me❤️👌 Thanks about giving your time to me⌚💋 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