Jump to content

Remove last word from string - (Moved)


Recommended Posts

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 post
Share on other sites

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?

Link to post
Share on other sites
Posted (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. :gathering:

Home > Scripting and Development > Developer General Discussion <== This is the wrong place for this type of question :ranting:

 

Edited by argumentum
grrr
Link to post
Share on other sites
  • Moderators

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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...