LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Add zeros in front of a string

    Employee
    Posted 08-05-2014 02:22

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: epetrou

    Hello,


    i have a string column which contains various numbers with various length.i am trying to fix these numbers by first defining their length and then adding that much zeros in front of them until i reach the correct length defined by me. for example i have the number "59664" as string.the length i consider "correct" is 9.so the said number should add that many zeros in front until it reaches the length of 9 aka -> "000059664".

    Since i have various lengths i'm first using a strlen function

    newafm='VAT registration number (AFM)'.strlen()

    and then im trying to split them depending on how many zeros i need to add.

    if newafm==9 then
    AFM='VAT registration number (AFM)' ( keep the correct number as it is)
    else if newafm=8 then
    AFM= (insert 1 zero) + ('VAT registration number (AFM)') /* add 1 zero */
    else if newafm=7 then
    AFM= (insert 2 zero) + ('VAT registration number (AFM)') /* add 2 zeros and so on */

    of course its pseudo code,im wondering if you have any simple solutions.I cant use replace since i dont have anything to replace,or split since i dont want the number to be split.


  • 2.  RE: Add zeros in front of a string

    Employee
    Posted 08-05-2014 02:40

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    Have you looked at the pad function?
    I think this does exactly what you're after.

    Example:
    newValue = 'VAT registration number (AFM)'.pad(9)
    emit newValue
    Tim


  • 3.  RE: Add zeros in front of a string

    Employee
    Posted 08-05-2014 03:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: epetrou

    Originally posted by: Tim Meagher
    					

    Hey,

    Have you looked at the pad function?
    I think this does exactly what you're after.

    Example:
    newValue = 'VAT registration number (AFM)'.pad(9)
    emit newValue
    Tim
    Thank you Tim,it works like a charm ! Is there anywhere i can get a full list of functions and a short description apart from the in-tool help ?


  • 4.  RE: Add zeros in front of a string

    Employee
    Posted 08-05-2014 03:16

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    Within BRE, if you are entering a value within a BRAINscript parameter, then you can right click and see the full list of operators available - sorted by the "type" of operator it is (e.g. Date and Time, Comparison, String Operators etc).
    When you start typing, you will have the autocomplete popup suggestions for the operator to use, and when you enter an open bracket, a list of the different ways that the function can be called will be displayed with a short description on each.

    Outside of BRE is the BRAINscript help, which is installed with the LAE.
    In order to access this, go to Help->BRAINscript help within BRE and a new browser window will open.
    If you want to access it without going through BRE, just bookmark it the first time you open it so you can access it more easily later.
    Within the BRAINscript help, all of the operators are listed on the left hand side of the page under "Content" - again split out into their different sections.
    If you want to checkout the whole list without clicking in each section, click the "Site Map" tab just next to "Content".
    Each of these links will take you to the full help for the operator, which generally includes a simple description, along with full discussion of the allowable arguments and examples.

    Tim.