Skip to main content
August 11, 2024
Question

Expression rule

  • August 11, 2024
  • 5 replies
  • 0 views

How to write a rule which takes two input a char and an integer,
ruleInput: (A,2)
Output: (A1;A2) 

anyone can give me the answer 

    5 replies

    August 12, 2024

    The requirement is not clear. Share more details.

    You can create a rule input of Text type and then pass comma-separated data in that.

    mikes0011
    Brainy
    August 12, 2024
    The requirement is not clear.

    I like defaulting to the laziest approach possible when the requirements aren't actually spelled out.  For instance, the result here is just a rule that returns "(A1;A2)", without specifying how the rule input (if any) is related to that (and my brain is too fried to try guessing).

    So here's my initial rule suggestion:

    "(A1;A2)"

    Straightforwardness: 10/10.  Flexibility for different rule inputs: ??/10.

    mikes0011
    Brainy
    August 12, 2024

    Less lazy reply:

    let's pretend the rule input is actually 2 inputs, a character and a "times repeated".  I don't feel like writing a parser to accept a comma-separated value when that may have just been OP overly abbreviating what their input is going to be.

    a!forEach(
      enumerate(ri!repeats),
      ri!character & fv!index
    )

    For "A" and 2, that gives us basically their prescribed output:

    For "C" and "11", it performs more of the same:

    konduruc733182
    August 12, 2024

    How are you passing this value?

    Also as Yogi Patel mentioned create a Rule input of text type and try this.

    a!localVariables(
      local!value: ri!ruleInput,
      local!integer: cleanwith(local!value, "1234567890"),
      local!alphabet: stripwith(local!value, "123456789(),"),
      local!listOfInt: enumerate(tointeger(local!integer)) + 1,
      a!forEach(
        items: local!listOfInt,
        expression: concat(local!alphabet, fv!item)
      )
    )

    I would ask you to please share what you have tried and what exactly is the requirement. 

    kumara0180
    August 12, 2024

    Hi, based on your input and output I am guessing you are trying to concatenate two inputs n number of times. if so, below snippet could be helpful

    for

    a!forEach(
      items: enumerate(ri!integer)+1,
      expression: concat(ri!text,fv!index)
    )