jsampsonyyyyy Posted December 14, 2020 Report Share Posted December 14, 2020 I am wondering if it is possible to delete the beginning of a string if it consists of a certain substring. E.g. if, and only if, the string begins with "Joe " then delete "Joe " leaving the rest of the string intact. I have found "replace" but that would remove "Joe " wherever it was in the string, not necessarily at the beginning. Quote Link to comment Share on other sites More sharing options...
rberq Posted December 14, 2020 Report Share Posted December 14, 2020 An integer variable may be set to the position of a substring within the text. So if you find it at position 1, then "replace". There's an option within "replace" to do it once only, or for all occurrences. Quote Link to comment Share on other sites More sharing options...
acantor Posted December 14, 2020 Report Share Posted December 14, 2020 This script illustrates one way to check for "Joe " at the start of the string: Quote Variable Set String %x% to "Joe Blow" Variable Set String %x%: Prompt Variable Modify String: Copy part of text in %x% starting at 1 and 4 characters long to %Name% If Variable %Name% Equals "Joe " Variable Modify String: Delete part of text from %x% starting at 1 and 4 characters long End If Text Box Display: Result Quote <VARIABLE SET STRING Option="\x00" Destination="%x%" Value="Joe Blow" NoEmbeddedVars="FALSE"/> <VARIABLE SET STRING Option="\x01" Destination="%x%" Prompt="What is the name?" Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%Name%" Variable="%x%" Start="1" Count="4" NoEmbeddedVars="FALSE"/> <IF VARIABLE Variable="%Name%" Condition="\x00" Value="Joe " IgnoreCase="FALSE"/> <VARIABLE MODIFY STRING Option="\x0A" Destination="%x%" Start="1" Count="4"/> <END IF/> <TEXT BOX DISPLAY Title="Result" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs20 The result is \"%x%\"\\lang1033\\f1\\fs14 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> Quote Link to comment Share on other sites More sharing options...
jsampsonyyyyy Posted December 14, 2020 Author Report Share Posted December 14, 2020 Just the thing - many thanks for this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.