Escape Sequences in Strings
Solutions
Solution 1 (Click to Show/Hide)
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
Hello!
I am stuck
var myStr = ‘FirstLine\n \SecondLine\ \r ThirsLine’; // Change this line
var myStr = ‘FirstLine\n \SecondLine\ \rThirsLine’; // Change this line
var myStr = ‘FirstLine\n \SecondLine\ \r ThirsLine’; // Change this line
var myStr = ‘FirstLine \n \SecondLine\ \rThirsLine’; // Change this line
What I can pass: myStr should have encoded text with the proper escape sequences and no spacing.
I tried this: var myStr = ‘FirstLine\n\SecondLine\\rThirsLine’; // Change this line
Also, evidently, I dont understand this sentence: Note that the backslash itself must be escaped in order to display as a backslash. )))
I also also stated reading the description of “Desing patterns” by Gang of Four, and programming seems not what it seemed. There is a reason why they pay good money! Because I dont understand what is inside Behavorial, Structural and Creational.
with best regards
happyMutant2
var myStr =“FirstLine\n\SecondLine\\rThirdLine”;
Try this code:
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;
var myStr= ‘FirstLine\n\\SecondLine\\rThirdLine’;
var myStr= ‘FirstLine\n\SecondLine\\rThirdLine’;
var myStr=“FirstLine\n\SecondLine\\rThirdLine”; // Change this line tip the ‘\r’ cannot use it in the end
These lesson clearly says that
FirstLine
newline
,backslash
SecondLinebackslash
,carriage-return
ThirdLine
It clearly show’s that we must first write:-
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine"
After writing FirstLine \n
which mean new line as given above followed by \SecondLine\ in order to escape from \ we use \
before and after of \SecondLine\ thus it become \SecondLine\and lastly carriage-return which is
\r` followed by ThirdLine.
var myStr = "FirstLine\n\\SecondLine\\\rThirdline";//doesn't tick the 1st box
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";//ticks all boxes
Can anyone explain what’s the difference between the 1st and 2nd lines?
You mean
var myStr = “FirstLine\n\SecondLine\rThirdline”;//doesn’t tick the 1st box
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;//ticks all boxes
? your strings the same
You initialise it in same line… Don’t declare in one line and initialize in another line…
The only difference in the second is that the three L’s in line are capital L’s. This drove me insane.
Hi,
There is no difference in escape sequences in these line in order to pass all test cases we must do what exactly they told it means even the string literal also. in your first var myStr the word Thirdline is the problem after you changed what exactly they asked it ticked all the boxes.
for anyone that is struggling with this was my answer:
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;
This works totally fine —
var myStr=“FirstLine\n\SecondLine\\rThirdLine”;
Thanks! I see know
Working! Spoiler adivise!
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;
var myStr = “FirstLine\n\SecondLine\\rThirdLine”; dis does the work for me after much brainstorming