Jump to content

Recommended Posts

Queener

I'm looking to delete string from point A to point B... For example:

"I want to go to store"

I would think I need 2 variables.

$sfind1 = want

$sfind2 = to.

Anything between $sfind1 and $sfind2 will be delete it.

 

I would think stringtrim left or right, but the problem I'm facing is, trim left/right does not have a point a or point b to trim from and to. It would be useful if a function was created to do this job if it doesn't already exist.


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
nitekram

Try stringmid()


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
Queener

don't think that is correct...

 

StringMid ( "string", start [, count = -1] )
There's no point b...
it can be used as
StringMid("I want to go to store", 3, 3)
this code would return 'wan'

 

The issue here is; it's not always going to be I want to go to store all the time. It will randomize any letters and alphabet later in the future.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
nitekram
Local $sString = "I want to go to store"

Local $sDeleteString =  StringMid($sString, StringInStr($sString, 'want'), StringInStr($sString, 'to'))

MsgBox('','', StringReplace($sString, $sDeleteString, ''))

 

If you want the second occurrence of the word 'to' it would be:

Local $sString = "I want to go to store"

Local $sDeleteString =  StringMid($sString, StringInStr($sString, 'want'), StringInStr($sString, 'to', 0, 2))

MsgBox('','', StringReplace($sString, $sDeleteString, ''))

 

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
mikell

The issue here is; it's not always going to be I want to go to store all the time. It will randomize any letters and alphabet later in the future.

Then a 'real' example is needed, because regular expressions can also do the job but they need precise requirements

Local $sString = "I want to go to store"

MsgBox('','', StringRegExpReplace($sString, 'I\h\K(.*?)\hto\h', "") )
MsgBox('','', StringRegExpReplace($sString, 'I\h\K(.*)\hto\h', "") )

 

Share this post


Link to post
Share on other sites
Queener

To make it easier identify, what about 

James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available.
replace after //[start] to before //[end] with nothing. So it should be 
Jame's PC at //[start] //[end] is not available

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
iamtheky
$sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available."

$sRepl = stringregexpreplace($sString , "\/\/\[start\].*\/\/\[end\]" , "")

msgbox(0, '' , $sRepl)

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
iamtheky

or this

$sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available."

msgbox(0, '' , _TrimFromAtoB($sString , "//[start]" , "//[end]"))

Func _TrimFromAtoB($string , $a , $b)
return stringleft($sString , stringinstr($sString , $a) - 1) & stringright($sString , stringlen($sString) - stringlen($b) - stringinstr($sString , $b))
EndFunc

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
mikell
$sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available."

$sRepl1 = stringregexpreplace($sString , "//\[start\]\h*\K.*(?=//\[end\])" , "")
msgbox(0, "" , $sRepl1)

$sRepl2 = stringregexpreplace($sString , "at\h*//\[start\].*//\[end\]" , "definitely")
msgbox(0, "" , $sRepl2)

:)
Is this example appropriate or do you want a generic way ?

Share this post


Link to post
Share on other sites
Queener

sorry, I just got off from work on my 2nd job so I haven't tested. Will let you know how it goes after testing it.

 

 

EDIT: Instead of using $sString; can I just have it look inside the file itself?

 

i tried this with no success:

 

 

$sFile = fileread($dummies)
$sRepl1 = stringregexpreplace($sFile , "//\[offstart\]\h*\K.*(?=//\[offend\])" , "")
;filewrite($dummies, $sRep11)
msgbox(0, "" , $sRepl1)

 

what i mean by no success is; it didn't modify anything... It sees the texts, but didn't replace it with empty after [offstart] and before [offend]

 

 

 

@boththose - your trim a to b works, but trimmed the whole [offstart] to [offend]. I actually want to leave those two for reference finding string next time I need to add more data.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
mikell

Hmm last try

$sRepl1 = stringregexpreplace($sFile , "(?s)(?<=//\[offstart\]).*?(?=//\[offend\])" , "")

 

  • Like 1

Share this post


Link to post
Share on other sites
Queener

Hmm last try

$sRepl1 = stringregexpreplace($sFile , "(?s)(?<=//\[offstart\]).*?(?=//\[offend\])" , "")

 

perfect!

 

Thank you guys so much for helping. I was pretty frustrated on getting it to work the way I wanted.


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
mikell

This still looks like a little wheel reinvention (because some people worked hard to provide nice includes)  :D

#include <String.au3>

$sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available."

$sRepl1 = StringReplace($sString , _StringBetween($sString ,"//[start]", "//[end]")[0] , " ")
msgbox(0, "" , $sRepl1)

 

Share this post


Link to post
Share on other sites
Queener

i can apply this to xml also right?


Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
mikell

The answer could be in your signature  :)

Share this post


Link to post
Share on other sites
Queener

hehehee... i used wrong... yes I can... though I'm not sure how to delete anything in between

 

<!--
 
-->
I tried
$sRepl1 = stringregexpreplace($sFileRead , "(?s)(?=<!--).*?(?=-->)" , "" & @CRLF & @CRLF & "")

It seems to elminate the <!-- and the data inside it, leaving out -->. Which I wanted to keep the <!-- and -->; just wipe out data in between those two.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites
mikell

There's a typo in your lookbehind
(?=<!--)    should be   (?<=!--)

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

  • Similar Content

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • CarlD
      By CarlD
      Is there a reliable way to ensure that data assigned to variables in a script is overwritten or deleted when the script exits? I have scripts that encrypt/decrypt data and would like to ensure, if possible, that the encryption keys and decrypted data do not stay in memory after the script exits. Thanks.
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
×