Position of spaces

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Position of spaces

Post by nodochau » Fri May 03, 2019 6:18 pm

Hello all,
Do you have any ideas of pointing out the position of all spaces in a sentence?
Ex: I go to Cali today.
I want to know all spaces position in that string.
Thanks a lot

User avatar
JRL
Automation Wizard
Posts: 3241
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Position of spaces

Post by JRL » Mon May 06, 2019 2:03 pm

Here's one possible way. Separate the string by internal variable %space%, then get the lengths of the separated words and do the math.

Code: Select all

Let>vString=I go to Cali today.
Separate>vString,space,var

Let>vSpacePositions=
Let>vTotal=0
Let>kk=0
Repeat>kk
  Add>kk,1
  Let>value=var_%kk%
  Length>value,vLen
  Add>vLen,1
  Add>vTotal,vLen
  Concat>vSpacePositions,%vTotal%%crlf%
Until>kk={%var_count%-1}

Let>Msg_Height=300
MDL>vSpacePositions

nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Re: Position of spaces

Post by nodochau » Mon May 06, 2019 2:42 pm

Thanks a lot.

nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Re: Position of spaces

Post by nodochau » Mon May 06, 2019 5:17 pm

Hi JRL,
Thank you for your code. It made my life easier.
I have sentence1: I go to Cali today. sentence2: I won't go to Cali tomorrow
I can use separate and position commands to find words in sentence 2 but not in sentence 1.
I get a problem is: How can I MDL all the words in separate lines at the end of the program
For Ex:
Words not in sentence 1 are:
won't
tomorrow
I appreciate your help

User avatar
JRL
Automation Wizard
Posts: 3241
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Position of spaces

Post by JRL » Tue May 07, 2019 2:50 am

I don't understand what you're asking.
If you want to know how to create a variable that contains the data you want displayed in a message look at the script created for your space positions. There is a variable called "vSpacePositions". Notice how it was developed and then used in the script. If that's not what you're looking for try explaining again.

nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Re: Position of spaces

Post by nodochau » Tue May 07, 2019 10:53 am

Here is my scripts:
Let>str1=I go to Cali today.
Let>str2=I won't go to Cali tomorrow.
Separate>str1,space,var1
Separate>str2,space,var2
Let>k=0
Repeat>k
Let>k=k+1
Position>var2_%k%,str1,1,pos
If>pos=0
MDL>var_%k% is not in str1
Endif.
Until>k={%var1_count%-1}
So I want to have a MDL which has all words that are not in str1 instead of the MDL show just one word at one loop.

User avatar
JRL
Automation Wizard
Posts: 3241
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Position of spaces

Post by JRL » Wed May 08, 2019 8:51 pm

I don't think you need space positions to do this. See code below.

Code: Select all

Let>str1=I go to Cali today.
//Use StringReplace> to clear out any potential punctuation from all strings
StringReplace>str1,.,space,str1
StringReplace>str1,comma,space,str1

Let>str2=I won't go to Cali tomorrow.
StringReplace>str2,.,space,str2
StringReplace>str2,comma,space,str2

//Use Separate> on str1 to create an array
Separate>str1,space,word1

//Use StringReplace> to format str2 words into a list
StringReplace>str2,space,crlf,str2

//Add crlf to top and bottom of list to isolate ell words.
Let>str2=%crlf%%str2%%crlf%

//Use Repeat loop to compare each word in the array to the words in the list
Let>ww=0
Repeat>ww
  Add>ww,1
  Let>value=word1_%ww%
  StringReplace>str2,%crlf%%value%%crlf%,%crlf%,str2
Until>ww=Word1_Count

//Regex> string to remove blank lines
RegEx>(?m)(^$\x0D\x0A)|(?-m)(\x0D\x0A)+$,str2,0,matches,num,1,,str2

mdl>str2

nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Re: Position of spaces

Post by nodochau » Thu May 09, 2019 3:18 pm

Hi JRL,
I appreciate your help.
It worked great for me.
Regex is the one that I need to learn how to use it. Can you please explain more about it? The help in MS does not help me much.
Thanks

User avatar
JRL
Automation Wizard
Posts: 3241
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Position of spaces

Post by JRL » Thu May 09, 2019 3:44 pm

Sorry, I am pitiful with regex. Jpuziano wrote this one (at my request) and posted it HERE.

User avatar
Grovkillen
Automation Wizard
Posts: 326
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Position of spaces

Post by Grovkillen » Thu May 09, 2019 5:17 pm

Buy RegexBuddy and you're a Regex-master in no time.
Let>ME=%Script%

Running: MS14.5.4

nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Re: Position of spaces

Post by nodochau » Fri May 10, 2019 10:16 am

Is it this?
I have text=abcdEFGH1234
can I set a pattern=(^a-z) to retrieve the EFGH1234 only? that what I've learned from regex101.com
Regex>pattern,text,0,matches,num,1,,text
?

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

Re: Position of spaces

Post by Dorian (MJT support) » Fri May 10, 2019 10:59 am

I'm no Regex guru either, but does this small edit to your original script do what you're looking for?

Code: Select all

Let>str1=I go to Cali today.
Let>str2=I won't go to Cali tomorrow.
Let>WordList=
Separate>str1,space,var1
Separate>str2,space,var2
Let>k=0
//mdl>%var2_count%
Repeat>k
Let>k=k+1
Position>var2_%k%,str1,1,pos
If>pos=0
Let>NewWord=var2_%k%
Concat>WordList,%NewWord%%space%
Endif.
Until>k=%var2_count%

mdl>WordList
Always accepting custom script commissions. Message me or go here

nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Re: Position of spaces

Post by nodochau » Mon May 13, 2019 12:58 pm

Thanks a lot Dorian. It worked for me and I have another problem to solve. I would like to separate lower case, uppercase and number. Example abcdEFGH03-25-2019.
Here is my code:
Let>text=abcdEFGH03-15-2019
Let>pattern=[^\d/-]
Regex>pattern,text,0,matches,num,1,,text1
MDL>text1
Let>pattern=[^a-z ]
Regex>pattern,text,0,matches,num,1,,text2
MDL>text2
text1 is 03-15-2019. I can get the result by using pattern=[^\d/-]
text2 is still abcdEFGH. I want text2 is abcd so that I can have three separate strings: abcd, EFGH and 03-15-2019
Since the length of letters in string is not determined so...
Thanks

hagchr
Macro Veteran
Posts: 266
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Position of spaces

Post by hagchr » Wed May 15, 2019 12:33 pm

I think you need to specify that you want the second regex to be case sensitive (ie A and a are not the same). You do that by adding the modifier (?-i) to the beginning of the pattern, ie change to Let>pattern=(?-i)[^a-z ]
(?-i really means turn off case insensitivity)

You can also search for all three blocks at the same time by using | (or) in the pattern. The results would then show up in matches_1, matches_2, matches_3 etc.

Code: Select all

Let>text=abcdEFGH03-15-2019
Let>pattern=(?-i)[a-z]+|[A-Z]+|[-\d]+
Regex>pattern,text,0,matches,num,0
MDL>Matches_1

nodochau
Newbie
Posts: 16
Joined: Wed Jan 16, 2019 12:59 pm

Re: Position of spaces

Post by nodochau » Wed May 15, 2019 3:45 pm

Thanks a lot hagchr.
It worked. Now I learn new stuff.

Post Reply