How to Convert an Array-Like String into an arraySplit a String into an array in Swift?Swift Convert A String-As-An-Array, To An Array Of StringsWhat is the difference between String and string in C#?Create ArrayList from arrayHow do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?Convert bytes to a string?Creating multiline strings in JavaScriptSort array of objects by string property valueHow to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?
How is total raw calculated for Science Pack 2?
How to annoymously report the Establishment Clause being broken?
Measure LiPo Battery Cells with Voltage Divider?
Why do many programmers abstain from using global variables?
Tiny image scraper for xkcd.com
Are there photos of the Apollo LM showing disturbed lunar soil resulting from descent engine exhaust?
How do you get the angle of the lid from the CLI?
Easy examples of correspondence between global and local, as preparation for Gauss's theorem and Stokes's theorem
How do I stop making people jump at home and at work?
Would there be balance issues if I allowed opportunity attacks against any creature, not just hostile ones?
What do I do when a crotchet is above a minim?
Visiting girlfriend in the USA
Declaring 2 (or even multi-) dimensional std::arrays elegantly
Why do old games use flashing as means of showing damage?
A question about dihedral group
Does the Scrying spell require you to have a clear path to the target in order to work?
How to get all months in a query where one month has no matches?
How do we know if a dialogue sounds unnatural without asking for feedback?
To which country did MiGs in Top Gun belong?
Punishment in pacifist society
Disney Musicians Ordering
Taking the first element in a list of associations
Can there be plants on the dark side of a tidally locked world?
Why not use futuristic pavise ballistic shields for protection?
How to Convert an Array-Like String into an array
Split a String into an array in Swift?Swift Convert A String-As-An-Array, To An Array Of StringsWhat is the difference between String and string in C#?Create ArrayList from arrayHow do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?Convert bytes to a string?Creating multiline strings in JavaScriptSort array of objects by string property valueHow to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a string that has the following value: " "OneV", "TwoV", "ThreeV" "
I was wondering if there was a way to take this string and convert it into an array that would have the follwing value: ["OneV", "TwoV", "ThreeV"]
arrays swift string swift4
add a comment |
I have a string that has the following value: " "OneV", "TwoV", "ThreeV" "
I was wondering if there was a way to take this string and convert it into an array that would have the follwing value: ["OneV", "TwoV", "ThreeV"]
arrays swift string swift4
which language are you using? what is the type of your string? are they all grouped in a single variable? type of the variable?
– ameerosein
Mar 28 at 2:17
@ameerosein The language is Swift. It's in the tags of the question.
– ayaio
Mar 28 at 12:42
add a comment |
I have a string that has the following value: " "OneV", "TwoV", "ThreeV" "
I was wondering if there was a way to take this string and convert it into an array that would have the follwing value: ["OneV", "TwoV", "ThreeV"]
arrays swift string swift4
I have a string that has the following value: " "OneV", "TwoV", "ThreeV" "
I was wondering if there was a way to take this string and convert it into an array that would have the follwing value: ["OneV", "TwoV", "ThreeV"]
arrays swift string swift4
arrays swift string swift4
edited Mar 28 at 12:39
ayaio
61.1k20 gold badges138 silver badges201 bronze badges
61.1k20 gold badges138 silver badges201 bronze badges
asked Mar 28 at 2:13
Anthony MartiniAnthony Martini
12 bronze badges
12 bronze badges
which language are you using? what is the type of your string? are they all grouped in a single variable? type of the variable?
– ameerosein
Mar 28 at 2:17
@ameerosein The language is Swift. It's in the tags of the question.
– ayaio
Mar 28 at 12:42
add a comment |
which language are you using? what is the type of your string? are they all grouped in a single variable? type of the variable?
– ameerosein
Mar 28 at 2:17
@ameerosein The language is Swift. It's in the tags of the question.
– ayaio
Mar 28 at 12:42
which language are you using? what is the type of your string? are they all grouped in a single variable? type of the variable?
– ameerosein
Mar 28 at 2:17
which language are you using? what is the type of your string? are they all grouped in a single variable? type of the variable?
– ameerosein
Mar 28 at 2:17
@ameerosein The language is Swift. It's in the tags of the question.
– ayaio
Mar 28 at 12:42
@ameerosein The language is Swift. It's in the tags of the question.
– ayaio
Mar 28 at 12:42
add a comment |
4 Answers
4
active
oldest
votes
Try this:
let aString = " "OneV", "TwoV", "ThreeV" "
let newString = aString.replacingOccurrences(of: """, with: "")
let stringArr = newString.components(separatedBy: ",")
print(stringArr)
If the sting not contains "
inside string then
let aString = "OneV,TwoV,ThreeV"
let stringArr = aString.components(separatedBy: ",")
print(stringArr)
add a comment |
swift
let str = ""OneV", "TwoV", "ThreeV""
let ary = str.components(separatedBy: ",")
add a comment |
To split a string into an array, you can use
string.split(separator: ",")
This will turn string from "1,2,3,4,5" to ["1","2","3","4","5"]
add a comment |
You could traverse the string with two pointers and look for characters between two double quotes (or any character of your choice) :
func substrings(of str: String, between char: Character) -> [String]
var array = [String]()
var i = str.startIndex
while i < str.endIndex
while i < str.endIndex, str[i] != char
i = str.index(after: i)
if i == str.endIndex break
i = str.index(after: i)
var j = i
while j < str.endIndex, str[j] != char
j = str.index(after: j)
guard j < str.endIndex else break
if j > i array.append(String(str[i..<j]))
i = str.index(after: j)
return array
And here are some use cases :
let s1 = ""OneV", "TwoV", "ThreeV""
substrings(of: s1, between: """) //["OneV", "TwoV", "ThreeV"]
let s2 = ""OneV", "TwoV", "Thr"
substrings(of: s2, between: """) //["OneV", "TwoV"]
let s3 = "|OneV|, |TwoV|, |ThreeV|"
substrings(of: s3, between: "|") //["OneV", "TwoV", "ThreeV"]
let s4 = "abcdefg"
substrings(of: s4, between: ",") //[]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389195%2fhow-to-convert-an-array-like-string-into-an-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this:
let aString = " "OneV", "TwoV", "ThreeV" "
let newString = aString.replacingOccurrences(of: """, with: "")
let stringArr = newString.components(separatedBy: ",")
print(stringArr)
If the sting not contains "
inside string then
let aString = "OneV,TwoV,ThreeV"
let stringArr = aString.components(separatedBy: ",")
print(stringArr)
add a comment |
Try this:
let aString = " "OneV", "TwoV", "ThreeV" "
let newString = aString.replacingOccurrences(of: """, with: "")
let stringArr = newString.components(separatedBy: ",")
print(stringArr)
If the sting not contains "
inside string then
let aString = "OneV,TwoV,ThreeV"
let stringArr = aString.components(separatedBy: ",")
print(stringArr)
add a comment |
Try this:
let aString = " "OneV", "TwoV", "ThreeV" "
let newString = aString.replacingOccurrences(of: """, with: "")
let stringArr = newString.components(separatedBy: ",")
print(stringArr)
If the sting not contains "
inside string then
let aString = "OneV,TwoV,ThreeV"
let stringArr = aString.components(separatedBy: ",")
print(stringArr)
Try this:
let aString = " "OneV", "TwoV", "ThreeV" "
let newString = aString.replacingOccurrences(of: """, with: "")
let stringArr = newString.components(separatedBy: ",")
print(stringArr)
If the sting not contains "
inside string then
let aString = "OneV,TwoV,ThreeV"
let stringArr = aString.components(separatedBy: ",")
print(stringArr)
answered Mar 28 at 2:23
Faysal AhmedFaysal Ahmed
4,3125 gold badges16 silver badges36 bronze badges
4,3125 gold badges16 silver badges36 bronze badges
add a comment |
add a comment |
swift
let str = ""OneV", "TwoV", "ThreeV""
let ary = str.components(separatedBy: ",")
add a comment |
swift
let str = ""OneV", "TwoV", "ThreeV""
let ary = str.components(separatedBy: ",")
add a comment |
swift
let str = ""OneV", "TwoV", "ThreeV""
let ary = str.components(separatedBy: ",")
swift
let str = ""OneV", "TwoV", "ThreeV""
let ary = str.components(separatedBy: ",")
answered Mar 28 at 2:27
SodaGun LegendarySodaGun Legendary
835 bronze badges
835 bronze badges
add a comment |
add a comment |
To split a string into an array, you can use
string.split(separator: ",")
This will turn string from "1,2,3,4,5" to ["1","2","3","4","5"]
add a comment |
To split a string into an array, you can use
string.split(separator: ",")
This will turn string from "1,2,3,4,5" to ["1","2","3","4","5"]
add a comment |
To split a string into an array, you can use
string.split(separator: ",")
This will turn string from "1,2,3,4,5" to ["1","2","3","4","5"]
To split a string into an array, you can use
string.split(separator: ",")
This will turn string from "1,2,3,4,5" to ["1","2","3","4","5"]
answered Mar 28 at 2:41
SalvadorioSalvadorio
12 bronze badges
12 bronze badges
add a comment |
add a comment |
You could traverse the string with two pointers and look for characters between two double quotes (or any character of your choice) :
func substrings(of str: String, between char: Character) -> [String]
var array = [String]()
var i = str.startIndex
while i < str.endIndex
while i < str.endIndex, str[i] != char
i = str.index(after: i)
if i == str.endIndex break
i = str.index(after: i)
var j = i
while j < str.endIndex, str[j] != char
j = str.index(after: j)
guard j < str.endIndex else break
if j > i array.append(String(str[i..<j]))
i = str.index(after: j)
return array
And here are some use cases :
let s1 = ""OneV", "TwoV", "ThreeV""
substrings(of: s1, between: """) //["OneV", "TwoV", "ThreeV"]
let s2 = ""OneV", "TwoV", "Thr"
substrings(of: s2, between: """) //["OneV", "TwoV"]
let s3 = "|OneV|, |TwoV|, |ThreeV|"
substrings(of: s3, between: "|") //["OneV", "TwoV", "ThreeV"]
let s4 = "abcdefg"
substrings(of: s4, between: ",") //[]
add a comment |
You could traverse the string with two pointers and look for characters between two double quotes (or any character of your choice) :
func substrings(of str: String, between char: Character) -> [String]
var array = [String]()
var i = str.startIndex
while i < str.endIndex
while i < str.endIndex, str[i] != char
i = str.index(after: i)
if i == str.endIndex break
i = str.index(after: i)
var j = i
while j < str.endIndex, str[j] != char
j = str.index(after: j)
guard j < str.endIndex else break
if j > i array.append(String(str[i..<j]))
i = str.index(after: j)
return array
And here are some use cases :
let s1 = ""OneV", "TwoV", "ThreeV""
substrings(of: s1, between: """) //["OneV", "TwoV", "ThreeV"]
let s2 = ""OneV", "TwoV", "Thr"
substrings(of: s2, between: """) //["OneV", "TwoV"]
let s3 = "|OneV|, |TwoV|, |ThreeV|"
substrings(of: s3, between: "|") //["OneV", "TwoV", "ThreeV"]
let s4 = "abcdefg"
substrings(of: s4, between: ",") //[]
add a comment |
You could traverse the string with two pointers and look for characters between two double quotes (or any character of your choice) :
func substrings(of str: String, between char: Character) -> [String]
var array = [String]()
var i = str.startIndex
while i < str.endIndex
while i < str.endIndex, str[i] != char
i = str.index(after: i)
if i == str.endIndex break
i = str.index(after: i)
var j = i
while j < str.endIndex, str[j] != char
j = str.index(after: j)
guard j < str.endIndex else break
if j > i array.append(String(str[i..<j]))
i = str.index(after: j)
return array
And here are some use cases :
let s1 = ""OneV", "TwoV", "ThreeV""
substrings(of: s1, between: """) //["OneV", "TwoV", "ThreeV"]
let s2 = ""OneV", "TwoV", "Thr"
substrings(of: s2, between: """) //["OneV", "TwoV"]
let s3 = "|OneV|, |TwoV|, |ThreeV|"
substrings(of: s3, between: "|") //["OneV", "TwoV", "ThreeV"]
let s4 = "abcdefg"
substrings(of: s4, between: ",") //[]
You could traverse the string with two pointers and look for characters between two double quotes (or any character of your choice) :
func substrings(of str: String, between char: Character) -> [String]
var array = [String]()
var i = str.startIndex
while i < str.endIndex
while i < str.endIndex, str[i] != char
i = str.index(after: i)
if i == str.endIndex break
i = str.index(after: i)
var j = i
while j < str.endIndex, str[j] != char
j = str.index(after: j)
guard j < str.endIndex else break
if j > i array.append(String(str[i..<j]))
i = str.index(after: j)
return array
And here are some use cases :
let s1 = ""OneV", "TwoV", "ThreeV""
substrings(of: s1, between: """) //["OneV", "TwoV", "ThreeV"]
let s2 = ""OneV", "TwoV", "Thr"
substrings(of: s2, between: """) //["OneV", "TwoV"]
let s3 = "|OneV|, |TwoV|, |ThreeV|"
substrings(of: s3, between: "|") //["OneV", "TwoV", "ThreeV"]
let s4 = "abcdefg"
substrings(of: s4, between: ",") //[]
answered Mar 28 at 8:32
ielyamaniielyamani
9,9156 gold badges33 silver badges69 bronze badges
9,9156 gold badges33 silver badges69 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389195%2fhow-to-convert-an-array-like-string-into-an-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
which language are you using? what is the type of your string? are they all grouped in a single variable? type of the variable?
– ameerosein
Mar 28 at 2:17
@ameerosein The language is Swift. It's in the tags of the question.
– ayaio
Mar 28 at 12:42