Jump to content

Remove string until character


Recommended Posts

I have looked different help files but havent find what i need. 

I have word  "  this is LOL word "  How to remove all string untill LOL included. I cant use StringRight($result2, 11) because text  " This is "  and  " word " can change to different words, only word " LOL is fixed

Edited by dersiniar
Link to comment
Share on other sites

  • Developers

Use StringInstr() to find the start of the word and then use StringMid() with the found start position. ;) 

Give it a try and post the code you tried that isn't working.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

11 minutes ago, Jos said:

Use StringInstr() to find the start of the word and then use StringMid() with the found start position. ;) 

Give it a try and post the code you tried that isn't working.

Hmm think that wont work cos i need to get that last word what comes after LOL. Since last word is changeable variable, cant use StringRight or anyother that depends on character count. 

Link to comment
Share on other sites

  • Developers

Yes it does because you know the length of the word you are searching!   So simply add that.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

10 minutes ago, Jos said:

Yes it does because you know the length of the word you are searching!   So simply add that.

 

16 minutes ago, dersiniar said:

Since last word is changeable variable,

No i do not know length, only thing is know is word LOL that's always there, And i need to get string that comes after it and that string is always different word and length. So is first string always different word and length

Link to comment
Share on other sites

  • Developers

Post your example code showing the issue with the different input strings and the expected output, after  which we can discuss this further, because I totally do not understand your point here as the StringInStr() will handle that variable prefix string length issue as far as I can see.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Or use a regex!

Local $sWord = "LoL"
Local $aIn = ["  this is LOL word ", "philology is LOL word ", " LOL this is Lol word "]
For $s In $aIn
    ConsoleWrite("'" & $s & "'  ->  '" & StringRegExpReplace($s, "(?i).*\b" & $sWord & "\b", "") & "'" & @LF)
Next

The trigger word can be any case but must be a separate word: "lol" in "philology" doesn't match. Only the last occurence of the trigger word counts. You may want to remove spaces from the output, or have other requirement. Just tell.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

19 hours ago, jchd said:

Or use a regex!

Local $sWord = "LoL"
Local $aIn = ["  this is LOL word ", "philology is LOL word ", " LOL this is Lol word "]
For $s In $aIn
    ConsoleWrite("'" & $s & "'  ->  '" & StringRegExpReplace($s, "(?i).*\b" & $sWord & "\b", "") & "'" & @LF)
Next

The trigger word can be any case but must be a separate word: "lol" in "philology" doesn't match. Only the last occurence of the trigger word counts. You may want to remove spaces from the output, or have other requirement. Just tell.

I get error  

 ==> Variable must be of type "Object".:
For $s In $aIn
For $s In $aIn^ ERROR

Link to comment
Share on other sites

Works for me, clearly.

Copy/paste the exact content I posted in a new .au3 and run it verbatim.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Local $sWord = "LoL"
Local $aIn = ["  this is LOL word1 ", "philology is LOL word2 ", " LOL this is Lol word3 "]
For $s In $aIn
   ; ConsoleWrite("'" & $s & "'  ->  '" & StringRegExpReplace($s, "(?i).*\b" & $sWord & "\b", "") & "'" & @LF)
    $w = StringStripWS(StringTrimLeft($s, StringInStr($s, $sWord, 0, -1) + StringLen($sWord) -1), 3)
    ConsoleWrite("'" & $s & "'  ->  '" & $w & "'" & @LF)
Next

:P

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...