Database Questions

i got this question from interviewer whats wrong in this
Q - string.format(“Deva{0}”,“Good evng”)
i had given as below
A - string.format({0},“Deva”,“Good evng”)

can you correct what is the wrong part

Hi @devasaiprasad_K

  1. string.format("Deva{0}", "Good evng"):
  • "Deva{0}": This is the format string. The {0} is a placeholder that indicates where the first parameter passed to string.Format() should be inserted.
  • "Good evng": This is the actual value that will replace {0} in the format string.

So, it will replace {0} with "Good evng", resulting in the string "DevaGood evng".

  1. string.format({0}, "Deva", "Good evng"):

This expression seems to use an incorrect syntax. In UiPath, you should not use curly braces {} as separate parameters within the string.Format() method. Instead, you should provide the format string followed by the values to be inserted into the placeholders.

The correct way to use string.Format() in UiPath would be as shown in the first example above.

Hope you understand!!

Q - string.format(“Deva{0}”,“Good evng”)…
This statement seems to be correct. There is no issue with this

What is incorrect is the redundancy of the entire expression.
Concatenating to literals this way should be avoided as it adds nothing to the result compared to writing it out as one individual string.

If the interviewer wanted to use string.format anyways, the only thing that might be wrong with it if the desired result of the expression is different that the input is, as the syntax is correct.

For example if the desired output was “Good evng Deva”, the expression should have been:

  • String.Format(“{0} Deva”, “Good evng”)
  • or String.Format(“Good evng {0}”, “Deva”)
  • or String.Format(“{0} {1}”, “Good evng”, “Deva”)

depending on which component was to be considered ‘dynamic’.

So actually it was a poor question of the interviewer :slight_smile: