1

I have a string:

countries = "India,Bangladesh,Srilanka,South Africa,Australia,Canada"

I need to get an array from it:

countries = ["India","Bangladesh","Srilanka","South Africa","Australia","Canada"]

How I can do this?

2 Answers 2

4

By using the split method:

countries = countries.split(",")
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

countries = "India,Bangladesh,Srilanka,South Africa,Australia,Canada".split(',')

1 Comment

Or even better, don't have an intermediate string. Simply do what you are doing, as countries ="India,Bangladesh,Srilanka,South Africa,Australia,Canada".split(',')

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.