1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
-
|
|
|
|
|
|
|
|
|
|
|
!
-
|
|
|
|
|
|
!
-
|
|
-
|
|
!
-
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
!
|
-
|
|
|
-
|
-
|
|
!
!
| #module
#defcfunc strrep str _strin,str target,str replace
strin = _strin
position = 0
repeat
await 1
position1 = instr( strin, position, target )
if position1 = -1 : break
position += position1 strin = strmid( strin, 0, position) + replace + strmid( strin, position + strlen(target), strlen(strin) )
position += strlen( replace ) loop
return strin
#defcfunc cutwqt str _strin
strin = _strin
if strmid( strin, 0, 1 ) = "\"" {
strin = strmid( strin, 1, strlen(strin)-2 )
position = 0
repeat
await 1
position1 = instr( strin, position, "\"" )
if position1 = -1 : break
position += position1 if strmid( strin, position + 1, 1 ) = "\"" : p = 2 : else : p = 1
strin = strmid( strin, 0, position) + strmid( strin, position+1, strlen(strin) )
position += p loop
}
return strin
#global
#module
#defcfunc cell2str str _strin
strin = _strin
if strlen(strin)!0 {
strin = _strin
strsrch = "" : poke strsrch,0,10 strin = strrep( strin, strsrch, "\n")
strin = cutwqt( strin )
}
return strin
#global
#module
#deffunc csvstr2 array _arrayout, str _strin
strin = _strin
cellcnt = 0
flg = 0 st = 0 fcellend = 0 scln = 0
repeat
await 0
if strmid( strin, cellcnt, 1 ) = "\"" {
flg = 1 kugiri = "\""
} else {
flg = 0
kugiri = ","
}
if flg = 1 {
scln = 1 repeat
await
k = instr( strin, cellcnt + scln, "\"" )
if k!-1 {
scln += k + 1
if strmid( strin, cellcnt + scln, 1 ) = "," : break if strmid( strin, cellcnt + scln, 2 ) = "\n" : fcellend = 1 : break scln++
} else {
scln = strlen(strin) - cellcnt
fcellend = 1
break
}
loop
} else {
getstr stra, strin, cellcnt, ',' scln = strsize
if stat = ',' { scln--
} else { fcellend = 1
if stat = 13 : scln -= 2 }
}
_arrayout.cnt = strmid( strin, cellcnt, scln ) cellcnt += scln + strlen(kugiri) if fcellend ! 0 : st = cnt+1 : break
loop
return st
#global
#if 0
mes "--- strrep ---"
moji = "こんにちは"
target = "にちは"
rep = "ばんは"
strin = strrep( moji, target, rep)
mes moji
mes "置換:" + target + "→" + rep
mes strin
mes "\n--- cutwqt ---"
moji = "\"テスト\"\"文字列\"\"テスト\""
strin = cutwqt( moji )
mes "2重ダブルクォーテーションをカットする"
mes moji
mes strin
mes "\n--- cell2str ---"
moji = "\"mes \"\"ダブル,クォーテーション\"\" ;こんな感じで\""
strin = cell2str(moji)
mes moji
mes strin
mes "\n--- csvstr2 ---"
sdim a, 256, 10
moji = "123,45,678,9,テスト文字列,\"テスト,文字列\""
csvstr2 a, moji
r = stat
mes moji
repeat r
mes a(cnt)
loop
#endif
#if 0
sdim a,256,10
moji = "123,\"mes \"\"ダブル,クォーテーション\"\" ;こんな感じで\",456,789"
mes moji
csvstr2 a, moji r = stat
mes "---"
repeat r
mes "Index(" + cnt + ") : " + a(cnt)
loop
mes "---"
repeat r
mes "Index(" + cnt + ") : " + cell2str( a(cnt) )
loop
stop
#endif
|