Aliisonline Posted November 22, 2010 Share Posted November 22, 2010 Hi guys! Me thinking of a way to search within a string for a specific text and then copy all characters before the found text like:as For ExampleI have $title = "XXXXXXXXXXXXXXXXXXXXXX(theses X's can change in number).doc Microsoft Word"now i want to search within $title and then want to get the text before .doc.....Please keep this in mind that after .doc i sometimes face cases when there is (Read Only) which means that i can't do anything based on fixed length before and after .docMe simply want to copy all the text before .doc to a string. So i can use that later Link to comment Share on other sites More sharing options...
water Posted November 22, 2010 Share Posted November 22, 2010 Use something like#include <array.au3> $title = "XXXXXXXXXXXXXXXXXXXXXX(theses X's can change in number).doc Microsoft Word" $aSplitTitle = StringSplit($title, ".doc", 1) _ArrayDisplay($aSplitTitle) $aSplitTitle[1] will contain the required text. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
rudi Posted November 22, 2010 Share Posted November 22, 2010 Hi. This is a task for RegEx: $title="XXXXXXXXXXXXXXXXXXXXXX(theses X's can change in number).doc Microsoft Word" $title=StringRegExpReplace($title,"(?i)(.*)(?:\.doc.*)","$1") ConsoleWrite($title & @CRLF) Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Aliisonline Posted November 22, 2010 Author Share Posted November 22, 2010 Thanks GUYS. Well both ways are working. But want to ask something more about both. #include <array.au3> $title = "XXXXXXXXXXXXXXXXXXXXXX(theses X's can change in number).doc Microsoft Word" $aSplitTitle = StringSplit($title, ".doc", 1) _ArrayDisplay($aSplitTitle) ;IF HERE i type MsgBox (0, "Patient List", $aSplitTitle) then it don't display any valueAnd some confusion about the second one.Please can you point where can i read information about this (?i)(.*)(?:\.doc.*) I mean i want to read something about the usage of these wild cards. Link to comment Share on other sites More sharing options...
water Posted November 22, 2010 Share Posted November 22, 2010 (edited) ;IF HERE i type MsgBox (0, "Patient List", $aSplitTitle) then it don't display any value StringSplit returns an array so you have to change the statement to: MsgBox (0, "Patient List", $aSplitTitle[1]) Please can you point where can i read information about this (?i)(.*)(?:\.doc.*) I mean i want to read something about the usage of these wild cards.This is a regular expression pattern. Please see "StringRegExp" in the help file or here for more details. Edited November 22, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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