How to find position of curly braces {

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

How to find position of curly braces {

Post by nodochau » Thu Aug 05, 2021 2:35 pm

Hello all,
I have the text = {skjfhaf akdjfj}....rdrgjfgj
how to find the position of the curly braces {

Thanks

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

Re: How to find position of curly braces {

Post by Grovkillen » Thu Aug 05, 2021 2:39 pm

Use the position command.
Let>ME=%Script%

Running: 15.0.27
version history

nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

Re: How to find position of curly braces {

Post by nodochau » Thu Aug 05, 2021 4:37 pm

I used it but it did not know the {
pos>{,text,1,res,1 does not work

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

Re: How to find position of curly braces {

Post by Dorian (MJT support) » Thu Aug 05, 2021 7:19 pm

It's working for me in v 15.0.18.

left returns 1, right returns 16

Code: Select all

Let>text={skjfhaf akdjfj}....rdrgjfgj
pos>{,text,1,left
pos>},text,1,right
However, if I keep the spaces as per your example, both are 0

Code: Select all

Let>text = {skjfhaf akdjfj}....rdrgjfgj
pos>{,text,1,left
pos>},text,1,right
Unless i ignore spaces :

Code: Select all

let>ignorespaces=1
Let>text = {skjfhaf akdjfj}....rdrgjfgj
pos>{,text,1,left
pos>},text,1,right
Yes, we have a Custom Scripting Service. Message me or go here

nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

Re: How to find position of curly braces {

Post by nodochau » Fri Aug 06, 2021 10:56 am

Yes, right. The problem is spaces.
And I got another problem:
If I have a text like this: {30 - 25}
How can I use position command to find the curly brace?
That text will return a number 5 if I do let>text={30 - 25}

Thanks

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

Re: How to find position of curly braces {

Post by Dorian (MJT support) » Fri Aug 06, 2021 11:43 am

Code: Select all

let>text={"{30 - 25}"}
pos>{,text,1,left
pos>},text,1,right
...and this is a wild guess, but I am wondering if your goal is to find the value between the curly braces. Just in case you are, we can use the regex Marcus posted previously. I've used variables to aid understanding/clarity :

Code: Select all

let>mystring={"{30 - 25}"}
let>BEGINNING={
let>END=}
RegEx>(?<=%BEGINNING%).*?(?=%END%),mystring,0,matches,nm,0
mdl>%nm% matches %CRLF%%matches_1%
Yes, we have a Custom Scripting Service. Message me or go here

nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

Re: How to find position of curly braces {

Post by nodochau » Fri Aug 06, 2021 12:11 pm

Thanks Dorian!

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