Salesforce Certified Marketing Cloud Engagement Developer free question 4 / 10 · Domain 2: Programmatic Languages
A developer sets @code to "0312F-Gold" and outputs Substring(@code, 7) with no third parameter. What is printed?
- G, as the function returns a single character when a length is not given
- 0312F-, as the function returns the part of the string before the start position
- Gold, as the substring starts at position 7 and runs to the end of the string
- -Gold, as the first character of the string is position 0
Show the answer and explanation
Answer: C
Why this is correct
Substring() has a required start position and an optional length. In "0312F-Gold" the positions 1 to 6 are "0312F-", and position 7 is the letter G. With no length, the substring continues to the end of the string, so the output is "Gold".
Why the other options are wrong
"G, as the function returns a single character when a length is not given" … The page says that without a length the substring continues to the end of the string, so the result is not limited to one character.
"-Gold, as the first character of the string is position 0" … Positions are counted from 1, so position 7 is the letter G and the dash is position 6.
"0312F-, as the function returns the part of the string before the start position" … The function returns the portion of the string that begins at the start position. It does not return the part before it.
Key point
Without a length, Substring() runs from the start position to the end.