Dear Experts,
I have some Javascript code that reads and sometimes sets the content of
a textarea. I want this to be reasonably browser and platform
independent. My question is, what characters should I expect to find at
the end of a line? I suspect that I need to cope with either "\n" or
"\r\n"; can someone confirm?
Setting the content is more of a challenge. I don't want to have nasty
browser detection to select what to use for newlines. Is there one
newline pattern that is safe for all browsers?
Many thanks for any suggestions.
Phil. 6 2696
*** Phil Endecott escribió/wrote (Fri, 25 Aug 2006 20:27:34 GMT):
I have some Javascript code that reads and sometimes sets the content of
a textarea. I want this to be reasonably browser and platform
independent. My question is, what characters should I expect to find at
the end of a line? I suspect that I need to cope with either "\n" or
"\r\n"; can someone confirm?
As far as I know, you can find:
\n in Unix/Linux
\r in MacOS 9 or older
\r\n in MacOS X and Windows
And several Unicode line endings nobody uses. http://en.wikipedia.org/wiki/Line_endings
Setting the content is more of a challenge. I don't want to have nasty
browser detection to select what to use for newlines. Is there one
newline pattern that is safe for all browsers?
I've never had any problem just using \n in Windows or Linux, but I can't
tell about MacOS 9.
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Alvaro G. Vicario wrote:
*** Phil Endecott escribió/wrote (Fri, 25 Aug 2006 20:27:34 GMT):
>I have some Javascript code that reads and sometimes sets the content of a textarea. I want this to be reasonably browser and platform independent. My question is, what characters should I expect to find at the end of a line? I suspect that I need to cope with either "\n" or "\r\n"; can someone confirm?
As far as I know, you can find:
\n in Unix/Linux
\r in MacOS 9 or older
\r\n in MacOS X and Windows
And several Unicode line endings nobody uses.
Thanks. I have read that you may get \n in Mozilla, whatever OS it is
on. Best to split on any of them I think.
>Setting the content is more of a challenge. I don't want to have nasty browser detection to select what to use for newlines. Is there one newline pattern that is safe for all browsers?
I've never had any problem just using \n in Windows or Linux, but I can't
tell about MacOS 9.
*** Alvaro G. Vicario escribió/wrote (Fri, 25 Aug 2006 23:25:50 +0200):
\n in Unix/Linux
\r in MacOS 9 or older
\r\n in MacOS X and Windows
Typo (as usual in me):
\n in Unix/Linux and MacOS X
\r in MacOS 9 or older
\r\n in Windows
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
JRS: In article <W2************ ******@newsfe5-win.ntli.net>, dated Fri,
25 Aug 2006 20:27:34 remote, seen in news:comp.lang. javascript, Phil
Endecott <sp************ *******@chezphi l.orgposted :
>I have some Javascript code that reads and sometimes sets the content of a textarea. I want this to be reasonably browser and platform independent. My question is, what characters should I expect to find at the end of a line? I suspect that I need to cope with either "\n" or "\r\n"; can someone confirm?
That may not mean what you think it means.
You mean to ask whether you need to cope with both LF and CR LF, where
LF is ASCII 10 & CR is ASCII 13, respectively Unicode \u000A \u000D .
Note that you *might* also find just CR.
In Javascript string, \n means newline, whatever that is locally, LF or
CR LF or CR - so splitting on \n should always be right.
Note that \n is a line separator; a file or string may or may not have
\n before the first line or after the last.
If I'm wrong, then <URL:http://www.merlyn.demo n.co.uk/js-quick.htm>
buttons Pack & Indt may not work right on non-CRLF systems.
Indt now deals with many split-statement cases.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dr John Stockton wrote:
Phil Endecott posted :
>I have some Javascript code that reads and sometimes sets the content of a textarea. I want this to be reasonably browser and platform independent. My question is, what characters should I expect to find at the end of a line? I suspect that I need to cope with either "\n" or "\r\n"; can someone confirm?
That may not mean what you think it means.
You mean to ask whether you need to cope with both LF and CR LF, where
LF is ASCII 10 & CR is ASCII 13, respectively Unicode \u000A \u000D .
Note that you *might* also find just CR.
In Javascript string, \n means newline, whatever that is locally, LF or
CR LF or CR - so splitting on \n should always be right.
Oh dear, yet another complication.
So on Windows, a string containing "\n" is actually two characters? Try
this:
var s = "\n";
alert(s.length) ;
This message: http://lists.evolt.org/archive/Week-...22/182514.html
suggests that Mozilla and IE behave differently on windows.
Phil.
JRS: In article <nt************ ******@newsfe4-win.ntli.net>, dated Sat,
26 Aug 2006 21:57:39 remote, seen in news:comp.lang. javascript, Phil
Endecott <sp************ *******@chezphi l.orgposted :
>Dr John Stockton wrote:
>Phil Endecott posted :
>>I have some Javascript code that reads and sometimes sets the content of a textarea. I want this to be reasonably browser and platform independent . My question is, what characters should I expect to find at the end of a line? I suspect that I need to cope with either "\n" or "\r\n"; can someone confirm?
That may not mean what you think it means.
You mean to ask whether you need to cope with both LF and CR LF, where LF is ASCII 10 & CR is ASCII 13, respectively Unicode \u000A \u000D . Note that you *might* also find just CR.
In Javascript string, \n means newline, whatever that is locally, LF or CR LF or CR - so splitting on \n should always be right.
Oh dear, yet another complication.
So on Windows, a string containing "\n" is actually two characters? Try this:
var s = "\n"; alert(s.length );
I get 1.
We need to discriminate better in discussion between internal and
external representations of newline.
I have, in js-quick.htm, a textarea F.Code for execution.
Enter just "F.Code.value.l ength" and execute : I get result 19 ; add a
newline with the Enter key and execute : 21 ; another : 23.
Enter just "alert(F.Code.v alue.<ENTER>spl it(""))" and execute : result
shows two apparent newlines for the <ENTERkeystroke .
Enter just "alert(F.Code.v alue.<ENTER>spl it("\n"))" and execute : result
includes one apparent newline.
ISTM that the only really safe rule is that \n in a string outputs as
newline (probably always) and otherwise anything may happen!
To read a set of lines into an array, disregarding blank lines, I've
used return Ctrl.value.matc h(/([^\r\n]+)/g)
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dominik Jain |
last post by:
Hi!
We hope somebody can help me with the following:
We have a form through which unicode data might be submitted. We need to be
able to detect when this happens and, most importantly, we need to be able
to obtain the unicode character codes for each individual letter/symbol.
Is this possible in PHP? If so, can you please provide a short code snippet.
We looked at the mbstring extension but found nothing helpful, especially
|
by: aegis |
last post by:
7.4#1 states
The header <ctype.h> declares several functions useful for classifying
and mapping characters.166) In all cases the argument is an int, the
value of which shall be representable as an unsigned char or shall
equal the value of the macro EOF. If the
argument has any other value, the behavior is undefined.
Why should something such as:
tolower(-10); invoke undefined behavior?
|
by: Craig Wagner |
last post by:
I have a situation where I have a series of character codes stored in the
database. In some cases they are the ASCII value of the character, in other
cases they are the > 127 character code value that you use in combination with
the ALT key to enter special characters into a document (e.g. ALT+0147 and
ALT+0148 get you 'smart quotes').
I'm trying to figure out how (or if it's possible) to obtain the Unicode
equivalent of the character...
|
by: kurotsuke |
last post by:
I need to convert a sequence of keys presses on the keyboard into the
corresponding character code (UNICODE).
I'm intercepting the KeyUp event (using an external hooking library)
and need to get the corrisponding code, according to the user
keyboard. For example, if the user pressed SHIFT+a I need to get the
65 code
I'd also need to the the opposite thing, that is converting the
character UNICODE code to a sequence of key presses.
|
by: Marcel Saucier |
last post by:
Hello, I want to use the above characters codes chart but I dont know how to
set the typeface (documentation: The characters that appear in Windows above
127 depend on the selected typeface).
For example, when I print the chr(205), I am not getting the one shown in
the Chart 2 list...
A step by step approach will be appreciated (in a windows form application).
--
| |
by: simchajoy2000 |
last post by:
Hi,
I know what the ASCII Character Codes are for the 2nd and 3rd powers in
VB.NET but I can't find the 6th power anywhere - does anyone know what
it might be or if it even exists?
Joy
|
by: Dwight |
last post by:
Hi all,
How do you enter the character code for the symbol "2/3". I can enter the
codes for "1/2", "3/4", but not for any other fraction. tia
Dwight
|
by: jake |
last post by:
I am new to xml. I have a routine that parses xml files using a
regular XmlReader class. Unfortunately, the XmlReader chokes (throws
an exception) on character codes such as "É". I resorted to
streaming the file first and replacing all the character codes with
their corresponding characters (copying the file while replacing
character codes at the same time) just to get things going. In the
case of É I replaced it with...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |