Format Explanation

Hi all,
i didn’t understand very well the format method.
In particular, when it’s used?

And in this example: String.Format("{1} is {0}", “home”, “John”, “far away”, 0, 1)
The result is John is home
But why? Someone can explain me?
Thanks in advice

1 Like

Fine
let me explain
Her {0} and {1} are called place holders
Which will be replaced with the value mention in that position along the String.Format method
Here along the syntax
String.Format("{0} is {1}", “John”, “Home”, “far away”)

So that 0 and 1 will be replaced with its corresponding values like John for 0 and Home for 1
As John mentioned as first and home mentioned as second
So the output will be like
John is Home

For more details on such an example with uipath

Cheers @andreus91

2 Likes

Thanks for the explanation, now is more clear, so the 0,1 at the end are two value?
Only one more doubt, why i can do this? What is the common case of use?

Thanks

1 Like

Awesome
Yah {0} and {1} are called place holders and the values mentioned along the syntax in sequence will be placed in those places holders one by one

And for this

This can be mainly used when we have a template say for example in a mail body we got a body content template but few values like username and his details will differ for each user
In that case we can replace such places with place holders like
Hi {0},

My name is {1}.

Thanks,
{2}

So this can be kept in a text file and read with read text file activity and then we can pass that string variable as input to string.format method and mention that syntax in Body property of Send Mail activity

Cheers @andreus91

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.