Jump to content
Macro Express Forums

String manipulation


Recommended Posts

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...