Funtions

Hi,

I have a value like APPIAN123, need to display the output as APPIAN321

Guide me

  Discussion posts and replies are publicly visible

  • Hi, can you confirm the last number digit will be fixed all time or not?

  • It depends on what the rules are here governing the format of the value you're referencing:

    • is the whole thing always a fixed length?
    • is it always text (letters A thru Z (upper case? and/or a thru z? .(lower case)) followed by numbers (0 thru 9)?
    • are the lengths of the text and number parts always the same?
  • Hi stewart,

    - The whole length is not fixed, but the length of the number is the same(3)

    - Text is always A thru Z

  • +1
    Certified Senior Developer

    You can try something like this - 

    a!localVariables(
    local!a: "APPIAN123",
    local!numberList: touniformstring({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }),
    local!length: len(local!a),
    local!lengthArray: enumerate(local!length) + 1,

    /* Get all the letters array */
    local!lettersArray: a!forEach(
    items: local!lengthArray,
    expression: a!localVariables(
    local!item: index(local!a, fv!item, ""),
    if(
    contains(local!numberList, local!item),
    null,
    local!item
    )
    )
    ),
    local!lettersLength: length(local!lettersArray),

    /* Get all the numbers array */
    local!numbersArray: a!forEach(
    items: local!lengthArray,
    expression: a!localVariables(
    local!item: index(local!a, fv!item, ""),
    if(
    contains(local!numberList, local!item),
    local!item,
    null
    )
    )
    ),
    local!numbersLength: length(local!numbersArray),

    /* Get final output */
    local!actualLetters: concat(
    rdrop(local!lettersArray, local!numbersLength)
    ),
    local!actualNumbersArray: ldrop(local!numbersArray, local!lettersLength),
    local!actualNumbersReverse: concat(reverse(local!actualNumbersArray)),
    concat(
    local!actualLetters,
    local!actualNumbersReverse
    )
    )

  • Ok, so this is pretty straightforward. let's break it down into a smaller set of problems:

    1. we extract the numbers from the string - we can use fn!right() to do this since we know the number part is always the same (3)
    2. we can extract the text from the string - we can use fn!length() to establish how long the whole string is and then subtract 3, since we know the numbers will always be 3 long, and so use fn!left() to extract the characters
    3. we need to reverse the numbers - fn!reverse() will only work on an array so you can create an array of the numbers from the extract taken above and then reverse them
    4. you can then join the reversed numbers array so that it is now one string
    5. finally you can concatenate the two strings - the extracted characters part, and the reversed numbers string

    hopefully that'll give you a direction to solve this for yourself