回答編集履歴
2
追記
test
CHANGED
@@ -103,3 +103,153 @@
|
|
103
103
|
print(newStr)
|
104
104
|
|
105
105
|
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
==== 回答追記
|
110
|
+
|
111
|
+
カンマまでを文字列としたときのサンプル。あくまでサンプルなので〜省略
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
var array:Array<Array<String>> = [[],[],[],[],[],[]]
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
let str = "こんにちわ,,おはよう,,お疲れ様\nこんにちわ,また明日,,,お疲れ様\n"
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
var count = 0
|
126
|
+
|
127
|
+
var inputStr = ""
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
print(str)
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
for c in str {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
if(c == "\n"){
|
140
|
+
|
141
|
+
array[count].append(inputStr)
|
142
|
+
|
143
|
+
array[count+1].append("\n")
|
144
|
+
|
145
|
+
count = 0
|
146
|
+
|
147
|
+
inputStr = ""
|
148
|
+
|
149
|
+
continue
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
if(c == ","){
|
156
|
+
|
157
|
+
array[count].append(inputStr)
|
158
|
+
|
159
|
+
inputStr = ""
|
160
|
+
|
161
|
+
count += 1
|
162
|
+
|
163
|
+
}else{
|
164
|
+
|
165
|
+
inputStr += String(c)
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
print(array)
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
var newArray:Array<Array<String>> = []
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
for ar in array {
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
var delFlg = true
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
for a in ar {
|
190
|
+
|
191
|
+
if(a != ""){
|
192
|
+
|
193
|
+
delFlg = false
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
if(!delFlg){
|
202
|
+
|
203
|
+
newArray.append(ar)
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
print(newArray)
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
var newStr = ""
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
for i in 0...1 {
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
var flg = false
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
for newA in newArray {
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
if(newA[i] != "\n" && flg){
|
232
|
+
|
233
|
+
newStr += ","
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
flg = true
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
newStr += newA[i]
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
print(newStr)
|
254
|
+
|
255
|
+
```
|
1
コメントへの回答追記
test
CHANGED
@@ -1 +1,105 @@
|
|
1
1
|
単純に最初に思いつくのは各列の文字を1字ずつ順番に格納していって、最後まで格納し終わったときに全て空白のものを見つけて、それ以外を結合しなおして文字列を作り直せば良いのではないでしょうか。(もっと良い方法はありそうですがシンプルに考えると)
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
===コメントへの回答追記
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
今Xcodeの再インストール中でオンラインで打てるSwiftで打ったコードなので正しいのかわからないのと、結構適当に書いたので諸々あれですが、処理の流れの参考にだけ。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```
|
14
|
+
|
15
|
+
var array:Array<Array<String>> = [[],[],[],[],[],[],[],[]]
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
var str = "A,,,e,,\nAb,,,fg\n,bc,e,g\nAb,,efg\n"
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
var count = 0
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
for c in str {
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
array[count].append(String(c))
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
count += 1
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
if(c == "\n"){
|
40
|
+
|
41
|
+
count = 0
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
var newArray:Array<Array<String>> = []
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
for ar in array {
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
var delFlg = true
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
for a in ar {
|
62
|
+
|
63
|
+
if(a != ","){
|
64
|
+
|
65
|
+
delFlg = false
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
if(!delFlg){
|
74
|
+
|
75
|
+
newArray.append(ar)
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
var newStr = ""
|
84
|
+
|
85
|
+
var count2 = 0
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
for i in 0...3 {
|
90
|
+
|
91
|
+
for newA in newArray {
|
92
|
+
|
93
|
+
newStr += newA[count2]
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
count2 += 1
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
print(newStr)
|
104
|
+
|
105
|
+
```
|