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;








-3















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"]










share|improve this question


























  • 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

















-3















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"]










share|improve this question


























  • 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













-3












-3








-3








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"]










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












4 Answers
4






active

oldest

votes


















0















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)





share|improve this answer
































    0















    swift



    let str = ""OneV", "TwoV", "ThreeV""
    let ary = str.components(separatedBy: ",")





    share|improve this answer
































      0















      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"]






      share|improve this answer
































        0















        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: ",") //[]





        share|improve this answer



























          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
          );



          );













          draft saved

          draft discarded


















          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









          0















          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)





          share|improve this answer





























            0















            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)





            share|improve this answer



























              0














              0










              0









              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)





              share|improve this answer













              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)






              share|improve this answer












              share|improve this answer



              share|improve this answer










              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


























                  0















                  swift



                  let str = ""OneV", "TwoV", "ThreeV""
                  let ary = str.components(separatedBy: ",")





                  share|improve this answer





























                    0















                    swift



                    let str = ""OneV", "TwoV", "ThreeV""
                    let ary = str.components(separatedBy: ",")





                    share|improve this answer



























                      0














                      0










                      0









                      swift



                      let str = ""OneV", "TwoV", "ThreeV""
                      let ary = str.components(separatedBy: ",")





                      share|improve this answer













                      swift



                      let str = ""OneV", "TwoV", "ThreeV""
                      let ary = str.components(separatedBy: ",")






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 28 at 2:27









                      SodaGun LegendarySodaGun Legendary

                      835 bronze badges




                      835 bronze badges
























                          0















                          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"]






                          share|improve this answer





























                            0















                            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"]






                            share|improve this answer



























                              0














                              0










                              0









                              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"]






                              share|improve this answer













                              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"]







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 28 at 2:41









                              SalvadorioSalvadorio

                              12 bronze badges




                              12 bronze badges
























                                  0















                                  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: ",") //[]





                                  share|improve this answer





























                                    0















                                    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: ",") //[]





                                    share|improve this answer



























                                      0














                                      0










                                      0









                                      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: ",") //[]





                                      share|improve this answer













                                      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: ",") //[]






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 28 at 8:32









                                      ielyamaniielyamani

                                      9,9156 gold badges33 silver badges69 bronze badges




                                      9,9156 gold badges33 silver badges69 bronze badges






























                                          draft saved

                                          draft discarded
















































                                          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.




                                          draft saved


                                          draft discarded














                                          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





















































                                          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







                                          Popular posts from this blog

                                          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현