Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Using the Concat & Substring

Avatar

Former Community Member
Hello all,



Pretty simple question, just running into syntax errors.

I want to take the first letter of fields 1 and 2, and the 6, 9, and 3rd number of fields three. I can do this with a substring one at a time, but I need to this so it puts all of the values from the substr together, ex. 051097HT. This is Date of birth, and initials. How would I usr the Concat for this. My last attempt.

TextField1.rawValue = Concat(Substr (txtDOB.rawValue, 6,2),(Substr(txtDOB.rawValue,9,2)

This is not the complete solution, just 2 parts. Not sure how to write it to put it together.



TIA!!!



Rudy
4 Replies

Avatar

Level 4
Rudy,

The good news is that you don't need to use the concat function. You can add strings together just like they were numbers. Although if they are numbers, like you seem to have, you need to be a bit careful to make sure they are concatonated strings rather than added numbers. For example



str1 = "25";

str2 = "47";



str3 = str1.substr(0,1) + str2.substr(1,1);



This will give you a result of "27". the substr() function returns string objects so you don't have to worry about Acrobat thinking they are numbers and producing a result of "9".



Thom Parker

WindJack Solutions


www.windjack.com

Avatar

Former Community Member
Hi Thom!



Thank you for the quick response. I did try it your way, but still having some problem. This is my first day working with Designer.



//str1 = txtDOB.rawValue

//str2 = txtDOB.rawValue



TextField1.rawValue = substr(txtDOB.rawValue, 6,2)+ substr(txtDOB.rawValue, 9,2)

//TextField1.rawValue = str1.substr, (6,2)+ str2.substr, (9,2)



My attempts are above. The second string works, but adds the numbers like you said. I noticed you put substr after the value, I did it according the Adobe's help file. I have tried other combos, but still stuck. I know I'm close. :)



Any suggestions on where I'm going wrong.



Thanks!!!

Avatar

Level 4
Jim,

These string operations are part of Core JavaScript, not Acrobat. To learn about using string in the JavaScript language you should take a look at a JavaScript Language Reference. The O'Reilly book is the best but there are plenty of online resources as well.



>>TextField1.rawValue = str1.substr, (6,2)+ str2.substr, (9,2)



This line has a syntax problem, it should be



TextField1.rawValue = str1.substr(6,2)+ str2.substr(9,2);



To keep it from adding the numbers you can force the this expression into a string context like this



TextField1.rawValue = String(str1.substr(6,2))+ String(str2.substr(9,2));



OR



TextField1.rawValue = str1.substr(6,2).concat(str2.substr(9,2));



Thom Parker

WindJack Solutions


www.windjack.com

Avatar

Former Community Member
Hi Thom!



Thanks for your help. I understand why I was getting sysntax errors. In my language box it was selected as FormCalc. When I changed it to Java, it worked just fine. But I thought I was working in FormCalc because I had it selected, and I was refering to the FormCalc User ref that Adobe offers. Thanks for the tip on the book, I'll pick it up. And thank you for all your help!!!



Rudy