Connecting Tech Pros Worldwide Forums | Help | Site Map

How to split on a backslash '\' ?

oprah.chopra@gmail.com
Guest
 
Posts: n/a
#1: Mar 8 '08
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>

Lee
Guest
 
Posts: n/a
#2: Mar 8 '08

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.


--

SAM
Guest
 
Posts: n/a
#3: Mar 8 '08

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