Skip to main content
pd0001
May 11, 2022
Question

How we will covert ("INDIA") TO {"I","N","D","I","A"}

  • May 11, 2022
  • 16 replies
  • 0 views

How we will covert ("INDIA") TO {"I","N","D","I","A"}. How we will write in expression rule?

    16 replies

    richardm900458
    May 11, 2022

    Hi pd, 

    my solution:

    a!forEach(
      items: enumerate(len("INDIA"))+1,
      expression:charat( "INDIA", fv!item)
    )


    regards,
    Richard

    stefanhelzle0001
    Brainy
    May 11, 2022

    a!localVariables(
      local!string: "INDIA",
      charat(local!string, 1 + enumerate(len(local!string)))
    )

    richardm900458
    May 11, 2022

    ah nice to know.
    -> but again a function which is not really explained that its taking an array of integer as well.
    documentation says (integer) [emoticon:dbebcc234b5646ae9035b59f9b586acd]

    stefanhelzle0001
    Brainy
    May 11, 2022

    True. I complained about this at the Appian product team and the documentation team.

    May 11, 2022

    1st way:

    {
    a!localVariables(
    local!Arry: stripwith(trim("INDIA"), " "),
    local!len: len(local!Arry),
    a!forEach(
    items: enumerate(local!len) + 1,
    expression: a!forEach(
    items: local!Arry[fv!item],
    expression: fv!item
    )
    )
    )
    }

    2nd way:

    { a!localVariables( local!word: stripwith(trim("INDIA"), " "), char(code(local!word)), ) }

    mikes0011
    Brainy
    May 11, 2022

    Let me introduce you to "code()", which splits any string into an array of the character codes.  Then "char()" which, if applied to an array, provides the characters for those codes (but still in an array).

    char(code("INDIA"))

    Honestly with as much as certain people around here (*ahem*) obsess over coming up with the shortest-possible-code for things even at the sacrifice of any readability, I'm shocked nobody beat me to this [emoticon:c28b2e4cc20f4ba28d1befdba6bed29c]
    Edit to add: I see Bejjenki included something similar (but, strangely, more verbose for some reason) in his "2nd way" above. [emoticon:1435ff2429184e17bc948e4f19178e1e]

    The Expression Guru
    gopalk2865
    Participating Frequently
    May 11, 2022

    Before using code(), i was just using index(). [emoticon:6d505171faa4497c85c5ca27290c555d]

    mikes0011
    Brainy
    May 11, 2022

    Yeah - and on that note, I've always kinda wondered why there isn't a less-hacky way to convert a string into an array of letters/characters, honestly. Though char(code()) is pretty compact, and the need has been infrequent (if ever), so I don't really sweat it.

    The Expression Guru
    davel001150
    May 11, 2022

    char(code("INDIA"))

    Lol, sorry Mike.  Still need to know when you and Stephan sleep so I can try for 50 answers achievement.

    mikes0011
    Brainy
    May 11, 2022

    LOL, i'm just a lazy east coast 9-5er.  I usually have no visibility into community when my day's done [emoticon:4191f5ee34e248a29fa0dbe8d975f74a]

    The Expression Guru