Replace IF first character

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Replace IF first character

Post by Tourless » Mon Apr 10, 2023 2:28 pm

Hi Folks,

I'm working with StringReplace to remove a zero from a string but I only need it removed if it's the first character in the string (left to right). I have this...

Code: Select all

StringReplace>asof,0,,asof
which yields either this 09=9 or this 10=1. I need 09=9 and 10=10.

How do I isolate or test on only the first character?

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Replace IF first character

Post by Grovkillen » Mon Apr 10, 2023 3:12 pm

Tried RegEx?

^0+(?!$)

This pattern will find one or more leading zeros unless it's a single zero.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1380
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Replace IF first character

Post by Dorian (MJT support) » Mon Apr 10, 2023 3:24 pm

Grovkillen wrote:
Mon Apr 10, 2023 3:12 pm
Tried RegEx?

^0+(?!$)

This pattern will find one or more leading zeros unless it's a single zero.
I was trying to find the RegEx for that when your reply popped up. Thank you for that.

So using this example :

Code: Select all

Let>text=09
Let>pattern=[[:\<:]]0
Let>pattern=^0+(?!$)
RegEx>pattern,text,0,matches,num,1,,text
MessageModal>text
Also Format might help :

Code: Select all

Let>data=09
Format>%.1d,data,result
mdl>result
Yes, we have a Custom Scripting Service. Message me or go here

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: Replace IF first character

Post by Tourless » Tue Apr 11, 2023 6:56 pm

And thank you both for the replies :) Now I have two solutions to handle my problem!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts