String.format

Hi,
can anyone help me to solve this question from one of the lesson test?
The String.Format(“Input = {0} and Output = {1}”, “1”,”2”) expression returns the following text:
Options are as below:
1.Input = {0} and Output = {1}
2.Input = 1 and Output = 2
3.Input = 0 and Output = 0
4.Input = 1 and Output = 1

2 Likes

This is the answer.

Regards
Balamurugan

1 Like

can you explain that?I’m not getting how this string.format method works…

1 Like

Hi @kirti21,

Check these links…

http://www.visual-basic-tutorials.com/beginner/Formatting-Strings.html

Regards
Balamurugan

1 Like

4.Input=1 and Output=1

@ String.Format(“Input={0} and Output= {0}”,”1”,”2”)

Hello. Can you please (if u know) explain, what is it:

string.Format(“{0}\{1}”,output, System.DateTime.Now.ToString(“yyyy-MM-dd_hh-mm-ss”))

I am interesting in this part exactly: string.Format(“{0}\{1}”

is it boolean?
what is this \ doing?

thank you a lot!

3 Likes

1 Like

“{0}” and "{1} are references which indicates the index of values/variables declared after the coma (in your example: “,output, System.DateTime…”, so in “{0}{1}”, "{0} will be replaced by the value of output and "{1} will be replaced with the value of System.DateTime

Check these examples using the same output and System-DateTime values:

“{0}{1},…”: value of output\formated Current DateTime
“{0}{0},…”: value of output\value of output
“{1}{0},…”: formated Current DateTime\value of output
“{1}{1},…”: formated Current DateTime\formated Current DateTime

In these other examples…
string.Format(“{0}/{1}/{2}”,“One”,“Two”,“Three”): One/Two/Three
string.Format(“{2}/{0}/{2}”,“Three”,“One”,Two"): Two/Three/Two
string.Format(“{2}/{1}/{0}”,“AAA”,“BBB”,“CCC”): CCC/BBB/AAA
string.Format(“{2}/{4}/{3}/{1}/{0}”,“One”,“AAA”,“BBB”,“CCC”,“Two”): BBB/Two/CCC/AAA/One

Hope this helps :wink:

6 Likes

this answer is wrong.

Hi olgakozhina,

For your question if it is boolean it was not!
it means that the string.Format(“{0}{1}”
1.{0} = output
2.{1}=System.DateTime.Now.ToString(“yyyy-MM-dd_hh-mm-ss”)

3 Likes

You can refer to my coding like below:

Target >> Setting date to history file name
tmpHistoryFileName :“C:\RPA Dev\Monthly Report\FIT VA\201808\90_Copy_Log\Copy_Log_FIT-VA-JPY_{0}.xlsx”

Implementation:
String.Format(tmpHistoryFileName, nowDate.ToString(“yyyyMMdd”))

2 Likes

Err no its not? {0} refers to the first argument given which is “1”, and {1} refers to the second which is “2”. So we will have “Input = 1 and Output = 2”.
Otherwise please give a reason as to why you think its wrong :slight_smile:

@Pedro_Camara

Welcome to forums

Can you share me a screenshot how you are declaring the values in studio?

And what error are you facing?

Thanks

Hi, I’m not getting any error. My post is a reply to someone elses post where they say the answer someone gave is wrong, and I’m arguing that it isn’t.
You should be able to see the context by loading my post’s parent post?

Thanks!

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