Summary question:
How can I detect and remove an empty space or empty spaces at the end of a variable?
Explanation:
An email containing the following phrases are received and my script removes the parentheses and everything in it.
1000 3.5x2 Premium Business Cards ($39)
12in x 24in (+$1/per)
Free soft carry case (+$0)
these items all have the same number of spaces between the end of the product/product desc and the opening parentheses.
I've tried a number of things. I've added an arbitrary string, "pt8", to the end and then I do a position for %emptyspace%pt8
if it finds a positionPos>1 then I reduce the length by 1 and midstr it.
test script produces the following variables:
1000 3.5x2 Premium Business Cards
12in x 24in
Free soft carry c
I have no idea why it is killing the "ase" off of case.
the following code is the latest code I've tried because the simple stuff doesn't seem to work.
//read the line
ReadLn>%fileName%,%r%,productitemline2
//get length of that line
Length>%productitemline2%,productitemline2len
//get text from line omitting first 5 empty spaces
MidStr>%productitemline2%,6,%productitemline2len%,productitemext
//find parentesis in the line ( ( ( ( ( ( ( ( ( ( ( (
Position>%paren%,%productitemext%,1,productitemparentheses
//if parenthesis exists save order item
if>%productitemparentheses%>1
//set length of product item to omit parentheses & price
let>productitemparenthesespos=%productitemparentheses%-1
MidStr>%productitemext%,1,%productitemparenthesespos%,productItemAdmission
//remove space from productItemAdmission
let>productItemAdmission=%productItemAdmission%pt8
mdl>%productItemAdmission%
Position>%spacept8%,%productItemAdmission%,1,spacept8Pos
if>%spacept8Pos%>1
let>productitemparenthesespos2=%productitemparenthesespos%-1
MidStr>%productItemAdmission%,1,%productitemparenthesespos2%,productItemAdmission
mdl>1st trigger: length:%CRLF%%productitemparenthesespos2%%CRLF%%productitemext%%CRLF%%productItemAdmission%
else
MidStr>%productitemext%,1,%productitemparenthesespos%,productItemAdmission
mdl>2nd trigger: length:%CRLF%%productitemparenthesespos%%CRLF%%productitemext%%CRLF%%productItemAdmission%
endif
Remove Spaces at end of variable
Moderators: Dorian (MJT support), JRL
-
- Pro Scripter
- Posts: 82
- Joined: Mon Mar 24, 2014 12:15 pm
Re: Remove Spaces at end of variable
Hi Snickers,
If you're trying to remove trailing characters, have you considered trimming them off? https://www.mjtnet.com/manual/trim.htm. Shouldn't impact your variable of there isn't a trailing character
Dominic
If you're trying to remove trailing characters, have you considered trimming them off? https://www.mjtnet.com/manual/trim.htm. Shouldn't impact your variable of there isn't a trailing character
Dominic
Re: Remove Spaces at end of variable
That is the exact function I am looking for.
Thank you!
Thank you!
Re: Remove Spaces at end of variable
You could also use Separate> and Trim> to extract the order item:
(If there could be parentheses also in the order item then you would have to adjust the result eg through concatenating all items until the last left parenthesis. res_1 gives item 1, res_count gives the total number of separated items.)
Code: Select all
Let>x1= 1000 3.5x2 Premium Business Cards ($39)
Separate>x1,(,res
Trim>res_1,result
MDL>result
Re: Remove Spaces at end of variable
Dominic_Fichera,
Thank you for pointing out Trim. Seriously cleaned my code up!
hagchr,
using separate along with trim shortened my entire code by over 100 lines of code...taking into account each subroutine that included a search for parentheses and extra spaces.
I love how separate doesn't throw an error if the variable doesn't actually have a parentheses in it.
Big thanks guys!
Thank you for pointing out Trim. Seriously cleaned my code up!
hagchr,
using separate along with trim shortened my entire code by over 100 lines of code...taking into account each subroutine that included a search for parentheses and extra spaces.
I love how separate doesn't throw an error if the variable doesn't actually have a parentheses in it.
Big thanks guys!