1

I have a window folder path, example:

var text1 = "C:\Mine\2020\example.txt"

But when I print text1 to console, the result: "C:Mine‚0example.txt"

Note: text1 is information from another place. The above case is just an example.

I tried:

String.raw`${text1}`

The result is still: "C:Mine‚0example.txt"

Only when:

String.raw`C:\Mine\2020\example.txt`

The result is exactly what I need: "C:\Mine\2020\example.txt"

But my input is text1 variable. Is there any way to handle the text1 variable? Thanks for any help!

3 Answers 3

2

try this

Test code

const filePath = String.raw `C:\Mine\2020\example.txt`;

console.log(The file was uploaded from: ${filePath});

result The file was uploaded from: C:\Mine\2020\example.txt

enter link description here

Sign up to request clarification or add additional context in comments.

1 Comment

I have read this document before, but What I need is a way to handle the text1 variable.
2

Escape characters my friend.

var text1 = "C:\Mine\2020\example.txt"

Test Code used {

var text1 = "C:\\Mine\\2020\\example.txt";
alert(text1);

}

Result {

 C:\Mine\2020\example.txt

}

If you are unsure about escape characters check the below link. https://www.w3schools.com/js/js_strings.asp

6 Comments

Thank for your help. I know escape characters, but text1 variables are required as above question.
Does this help, it retains the normal string and makes it so you can edit the string as well as out put the string as normal without the escape characters? let text1 = String.raw C:\Mine\2020\example.txt; alert(text1); text1 = String.raw C:\Mine\2020\Changable.txt; alert(text1);
Please treat text1 as information obtained from another place and you cannot use it directly
Ok i dont think its possible, you need to explain how you are getting the data into javascript.
for example the "C:\Mine" the interpreter in javascript converts \M i think it converts it to \null and makes it null and blank etc and i dont think you can stop it from doing that before runtime of the interpreter for javascript. but there might be a solution pending on how you are getting the data and might be able to do it in a Safeway aka encoding or some method.
|
1

I guess it's useful

var text1 = "C:\\Mine\\2020\\example.txt"
console.log(text1)

1 Comment

Thank for your help. I know escape characters, but text1 variables are required as above question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.