View Full Version : Change special characters in a string
wintzell
01-09-2006, 04:28 PM
Hey all, kind of newb on this and hoping to get some help!
I want to change a specific character in a string.
"C:\Program\textfile.txt"
to
"C:/Program/textfile.txt"
How do I do that?
Thanks in advance
flashead
01-09-2006, 04:48 PM
Well, I've never come across this problem before.
Normaly I'd say to do this:var str_A = "C:\Program\textfile.txt";
var str_B = str_A.split("\").join("/");
But it seems the slash escapes the quotes. So you need to escape the slash with a slash in the original string:var str_A = "C:\\Program\\textfile.txt";
and then use the above code to replace the "\\" with "/",
So you end up with:var str_A = "C:\\Program\\textfile.txt";
var str_B = str_A.split("\\").join("/");
trace( str_B );
Hopefully adding those extra slashes is an option for you, otherwise I don't know how else to tackle this one.
wintzell
01-09-2006, 05:01 PM
Thank you very much for your help but I'm afraid I can't change the "str_A" data since it comes from a third party projector...
Anyone else know how to perhaps change the "/" into "//"? Or any other solution for this problem?
wintzell
01-09-2006, 05:18 PM
Seems like a " " made it work. . .?
var str_A = "C:\Program\textfile.txt";
var str_B = str_A.split("\ ").join("/");
It works fine now! Tnx for the help!
flashead
01-09-2006, 05:47 PM
When I trace 'str_B' with your code it gives me:
C:/rogram extfile.txt
wintzell
01-09-2006, 06:01 PM
When I trace 'str_B' with your code it gives me:
C:/rogram extfile.txt
Okey, that's very wierd, Cause I get it C:/Program/textfile.txt ... Maybe it's because I use Screenweaver?
what's even more wierd
in flash seams to by NO way to do that :p
woud realy like to see if somebody can do it !!!
flashead
01-09-2006, 06:14 PM
Ok, yeah part of that is that Flash's output renders \p and \t as tags i guess.
so maybe just adding that space is all you need to do... if it works it works.
Without the space you just end up with errors in Flash.str_A.split("\");
Gives you: "String literal was not properly terminated"
http://www.actionscript.org/forums/showthread.php3?p=435285#post435285
tocoinaphrase
02-15-2006, 06:26 PM
Hey all, kind of newb on this and hoping to get some help!
I want to change a specific character in a string.
"C:\Program\textfile.txt"
to
"C:/Program/textfile.txt"
How do I do that?
Thanks in advance
When you specify a string litteral, you should simply create the string you want. Your original string should have been formatted as follows:
"C:\\program\\textfile.txt";
Note that back-slash characters are considered ESCAPE characters. For example \n means carrige return. The "\\" translates to a single '\'
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.