V
V
vasIvas2014-12-04 22:15:00
Programming
vasIvas, 2014-12-04 22:15:00

How to treat strings correctly?

1. How to properly consider line breaks?

// вариант 1
line1\n
line2\n
line3

// вариант 2
line1
\nline2
\nline3

2. What is meant when they say "delete a line"?
// вариант 1
line1\n
line3

// вариант 2
line1
\nline3

And unfortunately, I can't ask the third question yet, as it will depend on the
answers to these two, seemingly silly, but causing me questions, questions.
Let me explain what my difficulty is... If we consider strings as in the first example,
then the length of the string "line1\n" will be equal to six, just like the second. But if they tell me "delete the second line", as in the second version of the second question, then it turns out
that I have to delete one more character from the first line and at the same time I still incorrectly determine the index shift.
Once I asked this question and, as it seems now, they answered me incorrectly, thereby confusing me even more.
I'm sitting and I have a carousel with horses in my head that needs to be stopped,
but I can't do it myself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Lerg, 2014-12-04
@vasIvas

If the line break is visualized by its own escape sequence, then it is correct to consider the text as follows:
Line break is carried out after the line break character, so it remains at the end of the line.
The deletion of a line occurs together with the deletion of the hyphen character. If the transfer remains, then this is a line cleanup.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question