devxlogo

Trouble With String That Contains a Backslash

Question:
I get a string from the Microsoft Index Server like this: “Information uber”. If I try to assign this string to a variable I get a runtime error: “Invalid character.”

var str = "<%String see above%>

I think the problem is that there’s only one backslash in this string, and so JavaScript assumes that it is an escape sequence, but u is not a valid escape sequence. Is there a way to convert this string, so that it includes two backslashes? I’m using Windows NT 4.0 and Internet Explorer 4.01.

Answer:
You’re right. The backslash character () has a special meaning in JavaScript. Dealing with a string constant (like the one you’re getting from Microsoft Index Server) that includes a single backslash is awfully problematic. Your best bet would probably be to try to somehow convince Index Server to add a second backslash to the string rather than trying to solve the problem through JavaScript.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.