Skip to main content
Everything became completely clear now, so I delete some content(which is completely useless now) including 2 photos.
Source Link
imida k
  • 4.4k
  • 10
  • 20

There are 3 kinds of line breaks

  1. \r
  2. \n
  3. \r\n

For windows, \r\n is standard.

Suppose that there is a file called document.txt, using \r or \r\n as line breaks.
Suppose that I open document.txt with a notepad program and select all text and Ctrl+C,
then create a string variable named mystring, in mathematica.

In[1]  mystring="paste, I mean ctrl+V here."

(note that the content of mystring is several lines.)

Then

In[2] StringCount[mystring, "\r"]
Out[2] 0

Looks like \r or \r\n are all replaced with \n automatically.

Q1) Does mathematica automatically change line breaks to \n?

It is a little surprising that mathematica, doesn't prohibit to use \r.

If you type '\r' with your fingers, when defining a string variable, it works.

Looks like unwanted line breaks change (every line break to \n) happen only when pasting clipboard content to mathematica.

Q2) Why does mathematica behave like this ? Is there an option to correct this phenomenon?

About comment : Thank you Ben Izd, but in my PC, ReadString doesn't replace \n with \r\n.
Evidence :

enter image description here

And the result of opening file3.txt in notepad++ is, just 2 lilnes, not 3 lines. enter image description here

There are 3 kinds of line breaks

  1. \r
  2. \n
  3. \r\n

For windows, \r\n is standard.

Suppose that there is a file called document.txt, using \r or \r\n as line breaks.
Suppose that I open document.txt with a notepad program and select all text and Ctrl+C,
then create a string variable named mystring, in mathematica.

In[1]  mystring="paste, I mean ctrl+V here."

(note that the content of mystring is several lines.)

Then

In[2] StringCount[mystring, "\r"]
Out[2] 0

Looks like \r or \r\n are all replaced with \n automatically.

Q1) Does mathematica automatically change line breaks to \n?

It is a little surprising that mathematica, doesn't prohibit to use \r.

If you type '\r' with your fingers, when defining a string variable, it works.

Looks like unwanted line breaks change (every line break to \n) happen only when pasting clipboard content to mathematica.

Q2) Why does mathematica behave like this ? Is there an option to correct this phenomenon?

About comment : Thank you Ben Izd, but in my PC, ReadString doesn't replace \n with \r\n.
Evidence :

enter image description here

And the result of opening file3.txt in notepad++ is, just 2 lilnes, not 3 lines. enter image description here

There are 3 kinds of line breaks

  1. \r
  2. \n
  3. \r\n

For windows, \r\n is standard.

Suppose that there is a file called document.txt, using \r or \r\n as line breaks.
Suppose that I open document.txt with a notepad program and select all text and Ctrl+C,
then create a string variable named mystring, in mathematica.

In[1]  mystring="paste, I mean ctrl+V here."

(note that the content of mystring is several lines.)

Then

In[2] StringCount[mystring, "\r"]
Out[2] 0

Looks like \r or \r\n are all replaced with \n automatically.

Q1) Does mathematica automatically change line breaks to \n?

It is a little surprising that mathematica, doesn't prohibit to use \r.

If you type '\r' with your fingers, when defining a string variable, it works.

Looks like unwanted line breaks change (every line break to \n) happen only when pasting clipboard content to mathematica.

Q2) Why does mathematica behave like this ? Is there an option to correct this phenomenon?

edited tags
Link
imida k
  • 4.4k
  • 10
  • 20
Tweeted twitter.com/StackMma/status/1406673234540511239
added 169 characters in body
Source Link
imida k
  • 4.4k
  • 10
  • 20

There are 3 kinds of line breaks

  1. \r
  2. \n
  3. \r\n

For windows, \r\n is standard.

Suppose that there is a file called document.txt, using \r or \r\n as line breaks.
Suppose that I open document.txt with a notepad program and select all text and Ctrl+C,
then create a string variable named mystring, in mathematica.

In[1]  mystring="paste, I mean ctrl+V here."

(note that the content of mystring is several lines.)

Then

In[2] StringCount[mystring, "\r"]
Out[2] 0

Looks like \r or \r\n are all replaced with \n automatically.

Q1) Does mathematica automatically change line breaks to \n?

It is a little surprising that mathematica, doesn't prohibit to use \r.

If you type '\r' with your fingers, when defining a string variable, it works.

Looks like unwanted line breaks change (every line break to \n) happen only when pasting clipboard content to mathematica.

Q2) Why does mathematica behave like this ? Is there an option to correct this phenomenon?

About comment : Thank you Ben Izd, but in my PC, ReadString doesn't replace \n with \r\n.
Evidence :

enter image description here

And the result of opening file3.txt in notepad++ is, just 2 lilnes, not 3 lines. enter image description here

There are 3 kinds of line breaks

  1. \r
  2. \n
  3. \r\n

For windows, \r\n is standard.

Suppose that there is a file called document.txt, using \r or \r\n as line breaks.
Suppose that I open document.txt with a notepad program and select all text and Ctrl+C,
then create a string variable named mystring, in mathematica.

In[1]  mystring="paste, I mean ctrl+V here."

(note that the content of mystring is several lines.)

Then

In[2] StringCount[mystring, "\r"]
Out[2] 0

Looks like \r or \r\n are all replaced with \n automatically.

Q1) Does mathematica automatically change line breaks to \n?

It is a little surprising that mathematica, doesn't prohibit to use \r.

If you type '\r' with your fingers, when defining a string variable, it works.

Looks like unwanted line breaks change (every line break to \n) happen only when pasting clipboard content to mathematica.

Q2) Why does mathematica behave like this ? Is there an option to correct this phenomenon?

About comment : Thank you Ben Izd, but in my PC, ReadString doesn't replace \n with \r\n.
Evidence :

enter image description here

There are 3 kinds of line breaks

  1. \r
  2. \n
  3. \r\n

For windows, \r\n is standard.

Suppose that there is a file called document.txt, using \r or \r\n as line breaks.
Suppose that I open document.txt with a notepad program and select all text and Ctrl+C,
then create a string variable named mystring, in mathematica.

In[1]  mystring="paste, I mean ctrl+V here."

(note that the content of mystring is several lines.)

Then

In[2] StringCount[mystring, "\r"]
Out[2] 0

Looks like \r or \r\n are all replaced with \n automatically.

Q1) Does mathematica automatically change line breaks to \n?

It is a little surprising that mathematica, doesn't prohibit to use \r.

If you type '\r' with your fingers, when defining a string variable, it works.

Looks like unwanted line breaks change (every line break to \n) happen only when pasting clipboard content to mathematica.

Q2) Why does mathematica behave like this ? Is there an option to correct this phenomenon?

About comment : Thank you Ben Izd, but in my PC, ReadString doesn't replace \n with \r\n.
Evidence :

enter image description here

And the result of opening file3.txt in notepad++ is, just 2 lilnes, not 3 lines. enter image description here

added 227 characters in body
Source Link
imida k
  • 4.4k
  • 10
  • 20
Loading
Became Hot Network Question
Source Link
imida k
  • 4.4k
  • 10
  • 20
Loading