Tony007 Posted May 18, 2021 Share Posted May 18, 2021 Hello, please I need your help. I have a sentence and I want to remove the last word. How can I do that? I've already started a script. #include <MsgBoxConstants.au3> $Sentence = "Monday Tuesday Wednesday Thursday Friday" $NewSentence = ;Delete last Word from String MsgBox($MB_SYSTEMMODAL, "", $NewSentence) ;Result should be "Monday Tuesday Wednesday Thursday" Can anyone point me in the right direction? Thank you in advance Link to comment Share on other sites More sharing options...
Danp2 Posted May 18, 2021 Share Posted May 18, 2021 You should be able to use the StringInStr function with an occurrence of -1 for find the last space in the original string. With that number, you can then use StringLeft() or StringTrimRight() to remove the last word. I didn't bother checking, but I imagine there are already some examples on the forum that would show how to do this, perhaps with a single call to StringRegExpReplace. Did you try using the forum search feature? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
argumentum Posted May 19, 2021 Share Posted May 19, 2021 (edited) 2 hours ago, Danp2 said: You should be able to use the StringInStr function with an occurrence of -1 #include <MsgBoxConstants.au3> Global $Sentence = "Monday Tuesday Wednesday Thursday Friday" Global $NewSentence = StringLeft($Sentence, StringInStr($Sentence, " ", 0, -1)-1) MsgBox($MB_SYSTEMMODAL, "", '>' & $NewSentence & '<') ;Result should be "Monday Tuesday Wednesday Thursday" 2 hours ago, Tony007 said: please I need your help. ... I've already started a script. ...and that's why I posted. You showed initiative. ( and SciTE was already open ) It takes time. Home > Scripting and Development > Developer General Discussion <== This is the wrong place for this type of question Edited May 19, 2021 by argumentum grrr Tony007 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 19, 2021 Share Posted May 19, 2021 (edited) @Tony007 This function should do what you asking for, as well as the above script that @argumentum kindly posted: Func _RTrimWord($strString) Return StringRegExpReplace($strString, '\s*\S+$', '') EndFunc Edited May 19, 2021 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 19, 2021 Moderators Share Posted May 19, 2021 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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