216k views
2 votes
Having:

string S1 = "We plan our weekend";
string S2 = "first we will go to shopping mall"; string S3 "then we will have dinner";
string S;
what will be in S after each of the following:
1. SS1.concat(" and we will enjoy it");
2. S = S1 + S2;
3. SS1+ "," + S2;
4. SS1.concat("\\" + S2+" and buy things\\" + S3);
5. SS1.Substring(5);
6. SS2.Substring(4,12);

1 Answer

3 votes

Final answer:

In this question, we are manipulating string variables to update the value of string S using various operations such as concatenation and substring extraction.

Step-by-step explanation:

In each scenario, we will be manipulating the string variables to update the value of string S. Let's take a look at each scenario:

  1. In SS1.concat(" and we will enjoy it"), SS1 is concatenated with the specified string, resulting in a new string which will be assigned to string S.
  2. In S = S1 + S2, the strings S1 and S2 are concatenated and the result will be assigned to string S.
  3. In SS1 + "," + S2, the string SS1 is concatenated with a comma and S2, and the resulting string will be assigned to string S.
  4. In SS1.concat("\\" + S2+" and buy things\\" + S3), the strings SS1, S2, and S3 are concatenated with newline characters and the resulting string will be assigned to S.
  5. In SS1.Substring(5), a substring starting at index 5 of the string SS1 will be extracted and assigned to string S.
  6. In SS2.Substring(4,12), a substring starting at index 4 and ending at index 12 of the string SS2 will be extracted and assigned to string S.
User Sabiland
by
7.7k points