Viewpoint Forums
Viewpoint Forums
JavaScript
Load new scene using a network path|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Member |
Hi,
This is a somewhat wordy answer, because I'll put it into the FAQ's. You've come across an old problem with sz strings (strings terminated by zero) that started with 'C' and is inherited by JavaScript. When you want to put a special character into one of these strings, like a line-feed for example, you "escape" it by putting a backslash before it. Whenever the string parsing functions encounter a "\" backslash within a string, they look at the next character to see if it's one of the known special characters. If it sees "Hello\nWorld" then in place of the \n, it inserts line feed character. So if your string (your network path) has backslashes in it, you can see how the string parser is going to be constantly looking at the characters following the backslashes. In some cases it will see a character it doesn't recognize as having special meanings and totally ignore it, in other cases (like \t and \n for example) it will convert it into the special codes required (for tab and linefeed for example). So because backslash has this special meaning, they had to come up with a way of being able to put a backslash into the string, simple, escape it with a backslash. So for every backslash you want in a string, you need two e.g.: "\\\\myserver\\subdir1\\subdir2" Likewise, if you wanted to set a property into an MTX file using vmp.SetProperty, and the string you wanted to have set is "Hello\nWorld", then you'd need to set it to: vmp.SetProperty(~,~,"Hello\\nWorld",~); This way, the backslash did actually make it into the XML scene unconverted. It can get worse too. I recall having to do something like this for one case. If you were doing that setproperty with the property coming in through a function call, you'd would need to double up again e.g.: function myfunc(x) { vmp.SetProperty(~,~,x,~); } myfunc("Hello\\\\nWorld"); This may not always be necessary, but it's worth keeping in mind, as it may solve a problem one day. -Derek |
|||
|
|
Member |
I am a little confused reading your letter, but still I got the essence.
My concern comes from accessing javascript from c#.net. In that case I found that replacing \ with \\\\ would do the trick when calling the javascript function |
|||
|
|
Junior Member |
private static string NormalizeScript(string source) { return source.ToString().Replace("\"", "\\\"").Replace("\"", "\\\""); } |
|||
|
| Powered by Eve Community |
| Please Wait. Your request is being processed... |
|
Viewpoint Forums
Viewpoint Forums
JavaScript
Load new scene using a network path
