Jump to content
Sign in to follow this  
Queener

Delete String

Recommended Posts

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

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

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

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

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
$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

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
$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

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

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

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

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

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      goodmorning autoit team
      today am comming with some winhttp problems, i hope that you can help me to solve them.
      the first problem
      is when opening a request
      my forums api allow me to delete any post using the api key
      all functions work, i mean post / get
      but when i tried to use the delete verb it's gave me an html 404 error
      here is what am tried
      #include "WinHttp.au3" ; Open needed handles Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "xxxxxxxx.com") ; Specify the reguest: Global $hRequest = _WinHttpOpenRequest($hConnect, "Delete", "/vb/Api/posts/10447/?hard_delete=true", default, default) _WinHttpAddRequestHeaders($hRequest, "XF-Api-Key:xxxxx") _WinHttpAddRequestHeaders($hRequest, "XF-Api-User:xxxxx") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Global $sHeader = 0, $sReturned = 0 ; If there is data available... If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_DISPOSITION) ;Or maybe: ; $sHeader = _WinHttpQueryHeaders($hRequest, BitOR($WINHTTP_QUERY_RAW_HEADERS_CRLF, $WINHTTP_QUERY_CUSTOM), "Content-Disposition") Do $sReturned &= _WinHttpReadData($hRequest) Until @error msgBox(64, "", $sReturned) endIf ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen)  
      and here is the error message
      <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /vb/Api/posts/10447/ on this server.<br /> </p> </body></html>  
      i hope you can help me 
      thanks in advance
    • By cruisepandey
      Hi, 
      I have a string like this : 
      Global $Msga = "urrent directory is /send.  (Submission of file with log number 29381077284 is confirmed)";
      I want to extract the number 29381077284  from the string. I did StringSplit to split based on "(" and then use space to reach there, But it's not a good choice. 
      Can anyone help me with regular expression to find the number from String using AutoIT. TIA
    • By DannyJ
      I have this example string:
       
      2020-06-08 09:23:33 : abcdefghifjklm How to trim just the right part? Or how to trim this text right to left?
      I want to trim this string right to left until ' : '.
      In ohter words: I need the 'abcdefghifklm' text.
      I have tried StringTrimRight, but that requires 
      The number of characters to trim. Unfortunately StringSplit trims the left part of the strings.
       
       
    • By careca
      This is my take on string triggers, triggers on specific strings.
      Able to simple text pasting,
      opening links (as long as there's a www. http:\\ or https:\\ at the beggining)
      and is able to open applications, if there is a parameter in the parameter field, it uses it.
      Shows your external, lan, and gateway ip's.
      Able to change system volume by a set percentage, reading from the inputbox the number the user sets, if 0 or empty uses system default.
      I made this because the existing string trigger applications didn't do it for me.
      I did this for me, but if someone finds it useful, all the better.
×
×
  • Create New...