Asked  6 Months ago    Answers:  5   Viewed   18 times

How are r and n different? I think it has something to do with Unix vs. Windows vs. Mac, but I'm not sure exactly how they're different, and which to search for/match in regexes.

 Answers

49

They're different characters. r is carriage return, and n is line feed.

On "old" printers, r sent the print head back to the start of the line, and n advanced the paper by one line. Both were therefore necessary to start printing on the next line.

Obviously that's somewhat irrelevant now, although depending on the console you may still be able to use r to move to the start of the line and overwrite the existing text.

More importantly, Unix tends to use n as a line separator; Windows tends to use rn as a line separator and Macs (up to OS 9) used to use r as the line separator. (Mac OS X is Unix-y, so uses n instead; there may be some compatibility situations where r is used instead though.)

For more information, see the Wikipedia newline article.

EDIT: This is language-sensitive. In C# and Java, for example, n always means Unicode U+000A, which is defined as line feed. In C and C++ the water is somewhat muddier, as the meaning is platform-specific. See comments for details.

Tuesday, June 1, 2021
 
Sabya
answered 6 Months ago
20

Changed the HTML charset to ISO-8859-1 fixed the problem! Silly

Wednesday, March 31, 2021
 
Sujith
answered 9 Months ago
42

Short explanation:

If an algorithm is of ?(g(n)), it means that the running time of the algorithm as n (input size) gets larger is proportional to g(n).

If an algorithm is of O(g(n)), it means that the running time of the algorithm as n gets larger is at most proportional to g(n).

Normally, even when people talk about O(g(n)) they actually mean ?(g(n)) but technically, there is a difference.


More technically:

O(n) represents upper bound. ?(n) means tight bound. ?(n) represents lower bound.

f(x) = ?(g(x)) iff f(x) = O(g(x)) and f(x) = ?(g(x))

Basically when we say an algorithm is of O(n), it's also O(n2), O(n1000000), O(2n), ... but a ?(n) algorithm is not ?(n2).

In fact, since f(n) = ?(g(n)) means for sufficiently large values of n, f(n) can be bound within c1g(n) and c2g(n) for some values of c1 and c2, i.e. the growth rate of f is asymptotically equal to g: g can be a lower bound and and an upper bound of f. This directly implies f can be a lower bound and an upper bound of g as well. Consequently,

f(x) = ?(g(x)) iff g(x) = ?(f(x))

Similarly, to show f(n) = ?(g(n)), it's enough to show g is an upper bound of f (i.e. f(n) = O(g(n))) and f is a lower bound of g (i.e. f(n) = ?(g(n)) which is the exact same thing as g(n) = O(f(n))). Concisely,

f(x) = ?(g(x)) iff f(x) = O(g(x)) and g(x) = O(f(x))


There are also little-oh and little-omega (?) notations representing loose upper and loose lower bounds of a function.

To summarize:

f(x) = O(g(x)) (big-oh) means that the growth rate of f(x) is asymptotically less than or equal to to the growth rate of g(x).

f(x) = ?(g(x)) (big-omega) means that the growth rate of f(x) is asymptotically greater than or equal to the growth rate of g(x)

f(x) = o(g(x)) (little-oh) means that the growth rate of f(x) is asymptotically less than the growth rate of g(x).

f(x) = ?(g(x)) (little-omega) means that the growth rate of f(x) is asymptotically greater than the growth rate of g(x)

f(x) = ?(g(x)) (theta) means that the growth rate of f(x) is asymptotically equal to the growth rate of g(x)

For a more detailed discussion, you can read the definition on Wikipedia or consult a classic textbook like Introduction to Algorithms by Cormen et al.

Tuesday, June 1, 2021
 
John_BSDthos
answered 6 Months ago
55

rn is a Windows Style

n is a POSIX Style

r is a old pre-OS X Macs Style, Modern Mac's using POSIX Style.


r is a carrige return and n is a line feed, in old computers where it not have monitor, have only printer to get out programs result to user, if you want get printing from staring of new line from left, you must get n for Line Feed, and r for get Carriage return to the most left position, this is from old computers syntax saved to this time on Windows platform.

Wednesday, July 28, 2021
 
davidb
answered 4 Months ago
32

There are two key differences:

First, attributes assigned to a view via style will apply only to that view, while attributes assigned to it via android:theme will apply to that view as well as all of its children. For example, consider this style resource:

<style name="my_background">
    <item name="android:background">@drawable/gradient</item>
</style>

If we apply it to a LinearLayout with three child TextViews by using style="@style/my_background", then the linearlayout will draw with a gradient background, but the backgrounds of the textviews will be unchanged.

If instead we apply it to the LinearLayout using android:theme="@style/my_background" then the linearlayout and each of the three textviews will all use the gradient for their background.

The second key difference is that some attributes only affect views if they are defined in that view's theme. For example, consider this style resource:

<style name="checkboxes">
    <item name="colorAccent">#caf</item>
    <item name="colorControlNormal">#caf</item>
</style>

If I apply this to a CheckBox using style="@style/checkboxes", nothing will happen. If instead I apply it using android:theme="@style/checkboxes", the color of the checkbox will change.

Just like the first rule said, styles containing theme attributes will apply to all children of the view with the android:theme attribute. So I can change the color of all checkboxes in a linearlayout by applying android:theme="@style/checkboxes" to my linearlayout.

Sunday, August 22, 2021
 
McAuley
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share