3

i want to encode this text from

2016, Odd Semester, Periode 1

to

2016%2C%20Odd%20Semester%2C%20Periode%201

but i can't encode the comma.

it show like this

2016,%20Odd%20Semester,%20Periode%201

here my code

var Term = '2016, Odd Semester, Periode 1'
encodeURI(Term);
4
  • 4
    use encodeURIComponent Commented Nov 22, 2016 at 9:00
  • 2
    or use encodeURIComponent instead Commented Nov 22, 2016 at 9:00
  • 2
    This function encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters). Commented Nov 22, 2016 at 9:01
  • related post: stackoverflow.com/q/18251399/6908282 Commented Nov 12, 2024 at 18:20

2 Answers 2

5

Use encodeURIComponent():

var foo = encodeURIComponent('2016, Odd Semester, Periode 1');
console.log(foo);

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

Comments

1

Use encodeURIComponent(). It should suffice.

The encodeURIComponent() function encodes special characters. In addition, it encodes the following characters:

, / ? : @ & = + $ #

var Term = '2016, Odd Semester, Periode 1'
encodeURIComponent(Term);

Comments

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.