String manipulation2

Please help
A developer needs to create an automation process that identifies a file with the format “Monthly_Report_MMddyyyy.xlsx”. The file name is saved to a String variable called strInput. To extract the month (“MM”) from strInput, which String manipulation method will provide this information?

A. strInput.Substring(strlnput.LastIndexOf(”“)+1,2)
B. strInput.Substring(strlnput.IndexOf(”
“)+1,4)
C. strInput.Substring(strlnput.LastIndexOf(”“),2)
D. strInput.Substring(strlnput.IndexOf(”
"),8)

A developer needs to create an automation process that identifies a file with format “Monthly_Report_MMddyyyy.xlsx”. The file name is saved to a variable called strinput.
To extract the date from strinput, which string manipulation method should be used?
A. strinput.Substring(strInput.LastIndexOf(““)+1,8)
B. strinput.Substring(strInput.IndexOf(”
”)+1,strInput.IndexOf(“.”)−1)
C. strinput.Substring(strInput.IndexOf(““)+1.8)
D. strinput.Substring(strInput.IndexOf(”
”)+1,strInput.IndexOf(“.”))

First One:
A. strInput.Substring(strlnput.LastIndexOf("")+1,2)

Explanation: The LastIndexOf("") method returns the index of the last occurrence of an empty string, which in this case would be the position before the file extension “.xlsx”. Adding 1 to that index would point to the starting position of the month (“MM”) in the strInput. The Substring method is then used to extract the two characters representing the month.

Therefore, option A is the correct answer.

Second One:
B. strinput.Substring(strInput.IndexOf("") + 1, strInput.IndexOf(".") - strInput.IndexOf("") - 1)

Explanation: The IndexOf("") method returns the index of the first occurrence of an empty string, which in this case would be the position after “Monthly_Report_”. Adding 1 to that index would point to the starting position of the date in the strinput.

The IndexOf(".") method returns the index of the period (“.”) in the strinput, which indicates the end of the date portion. Subtracting the index of the empty string from the index of the period provides the length of the date portion.

Using the Substring method with the starting position and length, we can extract the date from strinput.

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