2012-01-10 12 views
0

私は、次の問題が生じています:)(スプリットからの結果を組み合わせる

次の文字列は、MS AccessのDB内のリンクテーブルを通じて取得されます。

string = Text1, Text2, Text3, "This, belongs, together", Text7, Text8, "This, Also, Belongs, Together", Text13, etc., etc., etc. 

引用されたフィールドがどのくらい彼らを変えることができますあります。

Split(string、 "、")を使用すると、13個の値が返され、置き換えても問題なく置き換えることができます。 私が直面している問題は、引用符間のテキストが1つの値であることです。 上記の例では、13の代わりに8つの値を取得する必要があります。これは、データベースへのINSERT INTOクエリに必要です。ここで

は、私はエラーを与える、これまでに得たものである:範囲外の添字 :「私は、」私は引用符で値を組み合わせることができる方法の任意の考え

SqlJunk = "SELECT * FROM Con_Temp" 
Set rsCon = Server.CreateObject("ADODB.Recordset") 
rsCon.Open SqlJunk, dbGlobalWeb, 3 

Do While Not rsCon.EOF 
Field = split(rsCon("Field1"),",") 
For i = 0 to UBound(Field) 
    If InStr(Field(i),"""") > 0 Then 
     Field(i) = Replace(Field(i), """", "") 
    End if 
    If Field(i) <> "" Then 
     If dbfields <> "" Then 
      dbfields = dbfields & ",[" & Conveldnaam(i) & "]" 
     Else 
      dbfields = "[" & Conveldnaam(i) & "]" 
     End if 
     If dbvalues <> "" Then 
      dbvalues = dbvalues & ",""" & Field(i) & """" 
     Else 
      dbvalues = """" & Field(i) & """" 
     End if 
    End if 
    response.write(dbfields) 
Next 
SQL = "INSERT INTO ConInventory (" & dbfields & ") VALUES (" & dbvalues & ")" 
response.write(SQL & "<br>") 
dbGlobalWeb.Execute(SQL) 
rsCon.MoveNext 
dbfields = "" 
dbvalues = "" 
Loop 

を?

ありがとうございます!

エリック

答えて

0

は、このロジックを試してみて、それに応じてコードを変更: -

Dim str, strArray, count, combineStr 
count = 0 
combineStr = "" 
str = "Text1, Text2, Text3, ""This, belongs, together"", Text7, Text8, ""This, Also, Belongs, Together"", Text13" 
strArray = split(str, ", ") 


For Each item In strArray 
    If (Left(item, 1) = """") Then 
     combineStr = combineStr & " " & item 
     count = 1 
    ElseIf (count = 1) Then 
     If (Right(item, 1) = """") Then 
      count = 0 
     End If 
     combineStr = combineStr & " " & item 
    End If 
    If (count = 0) Then 
     If (combineStr = "") Then 
      Response.Write("<br>" & item) 
     ElseIf (combineStr <> "") Then 
      Response.Write("<br>" & combineStr) 
      combineStr = "" 
     End If 
    End If 
Next 
+0

あなたは私のヒーローです!感謝万円!あなたが言ったようにそれを実装するためにいくつかの非常に小さな調整をしなければならなかったが、それは現在約90%のために働いている!あなたはちょうど私の一日を作った、もう一度感謝! – Meridius

関連する問題