Connecting Tech Pros Worldwide Help | Site Map

How to split on a backslash '\' ?

  #1  
Old March 8th, 2008, 05:45 AM
oprah.chopra@gmail.com
Guest
 
Posts: n/a
The following code does not seem to work, I have tried all
combinations of \\, \, \\\ etc. Unfortunately I can not change str .

<script type="text/javascript">

var str = 'Hello \ World';
var pattern = /\\/;
result = str.split( pattern );

alert(result[0]);

</script>
  #2  
Old March 8th, 2008, 05:55 AM
Lee
Guest
 
Posts: n/a

re: How to split on a backslash '\' ?


oprah.chopra@gmail.com said:
Quote:
>
>The following code does not seem to work, I have tried all
>combinations of \\, \, \\\ etc. Unfortunately I can not change str .
>
><script type="text/javascript">
>
>var str = 'Hello \ World';
>var pattern = /\\/;
>result = str.split( pattern );
>
>alert(result[0]);
>
></script>
alert the value of str.
You'll be surprised.


--

  #3  
Old March 8th, 2008, 10:55 AM
SAM
Guest
 
Posts: n/a

re: How to split on a backslash '\' ?


oprah.chopra@gmail.com a écrit :
Quote:
The following code does not seem to work, I have tried all
combinations of \\, \, \\\ etc. Unfortunately I can not change str .
>
<script type="text/javascript">
>
var str = 'Hello \ World';
var pattern = /\\/;
the right patern would have to be :

var pattern = /\ /;

because :

var str = 'Hello \ World';
^^
Quote:
result = str.split( pattern );
or :

result = str.split( '\ ' );

Quote:
alert(result[0]);
>
</script>
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Split Chinese Character with backslash representation? Wijaya Edward answers 8 October 27th, 2006 10:15 PM
Fwd: How to Split Chinese Character with backslash representation? limodou answers 0 October 27th, 2006 04:35 AM
Hot to split string literals that will across two or more lines ? Xiao Jianfeng answers 37 November 23rd, 2005 12:35 PM
Access expoert reports to PDF using PDF writer 6.0 issues Grasshopper answers 11 November 13th, 2005 07:08 AM