Jump to content

Recommended Posts

Posted

Hi,

I'm wanting to replace characters in a string which occure on more than 1 occasion, so for example if I have the following string.

XXXYYYYXXZZXXXXXUUU

So is there a function I can use to replace say 2 x's with the letter 'W' and 3 x's with the letter 'R' for example? but if there are 5 X's like in the example could this be replaced with the letters 'WR'

I had a look at all the string functions in the help file but I cant find anything that would be suitable. I essentially need to search the string starting from the beginning for the occurances because the string can change depending on some variables from the user.

 

Thanks

Posted (edited)

I think this should be possible with StringReplace. Start with the longest:

$sString = StringReplace($sString, "xxxxx", "WR")
$sString = StringReplace($sString, "xxxx", "??")
$sString = StringReplace($sString, "xxx", "R")
$sString = StringReplace($sString, "xx", "W")

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hi,

Thanks for that it works fine. I did originally try StringReplace but it didn't cross my mind to start with the longest string frist.

 

Thanks

Posted

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
×
×
  • Create New...