Sign in to follow this  
Followers 0
Aliisonline

want to search within a string

5 posts in this topic

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 Example

I 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 .doc

Me simply want to copy all the text before .doc to a string. So i can use that later

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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 value

And 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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0