Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Replace Characters
- From: twlewis at softhome.net (Tim Lewis)
- Subject: [Javascript] Replace Characters
- Date: Thu May 17 05:46:45 2007
Thank you David. I used your recommendation: sLineOut13 = sLineOut11.replace(/\u000d/g,'\u000d\u000a'); It works excellent. > On 16/05/07, Tim Lewis <twlewis@xxxxxxxxxxxx> wrote: >> I have a file with carriage returns(ASCII 13) only, and I need to >> replace >> these with carriage return and line feed(ASCII 13 and 10). >> >> My code was not work, so I created a simple test using the >> String.fromCharCode and replace. It is not working either. I have >> included the simple code below. The idea in the code is to replace the >> d >> in dog with an l. It appears that the replace function does not >> recognize >> an ASCII value. Is there a way to make the replace function use an >> ASCII >> value? > > Yes there is, but not through doing this: > >> sLineOut = sLineIn.replace(/chr100/g,chr108); > > You are here trying to replace any piece of the string that contains > one of each of the characters 'c', 'h', 'r', '1', '0' and '0', in that > order, with the value from the variable chr108. > > > You can't enter variables into regex, short of by using > > new RegExp(...) > > However, you can use the same character escapes in regex as you can in > JavaScript strings. CR is '\u000d', '\x0d', or '\r'. LF is '\u000a', > '\x0a' or '\n'. Note however that some browsers use '\n' in strings > for the platform convention line ending and not for LF, so in this > case I'd recommend you to use the unicode literal. > -- > David "liorean" Andersson > _______________________________________________ > Javascript mailing list > Javascript@xxxxxxxxxx > https://lists.LaTech.edu/mailman/listinfo/javascript >
- References:
- [Javascript] Replace Characters
- From: Tim Lewis
- [Javascript] Replace Characters
- From: liorean
- [Javascript] Replace Characters
- Prev by Date: [Javascript] Replace Characters
- Next by Date: [Javascript] While statement array losing data
- Previous by thread: [Javascript] Replace Characters
- Next by thread: [Javascript] While statement array losing data
- Index(es):