Swift Text File To Array of Strings

后端 未结 6 1362
逝去的感伤
逝去的感伤 2021-01-01 22:20

I was wondering what the simplest and cleanest to read a text file into an array of strings is in swift.

Text file:

line 1
line 2
line 3 
line 4
         


        
6条回答
  •  無奈伤痛
    2021-01-01 22:55

    Here is a way to convert a string to an array(Once you read in the text):

    var myString = "Here is my string"
    
    var myArray : [String] = myString.componentsSeparatedByString(" ")
    

    This returns a string array with the following values: ["Here", "is", "my", "string"]

提交回复
热议问题