Remove unnecessary chr (13) from csv line with classic asp (vbscript)

I want to create a classic asp (vbscript) function that replaces all the "returns" that occur between double quotes.

Input line: 'csv' like:

ID;Text;Number
1;some text;20
2;"some text with unwanted return
";30
3;some text again;40

I want to split a string into chr (13) (returns) to create separate rows in an array. It works well, with the exception of the unwanted chr (13), which is contained in the id 2 text.

Hope someone can help.

+3
source share
4 answers

In fact, this will be difficult to do, because you cannot determine whether the carriage return is valid or not. Obviously, after 20and 30valid.

, , . 3, . (, , , CSV ).

, , - , CSV, , ? , , , CRs.

CSV, . , " " / " " .

, , , ? , Excel SQL Server () .

+4

CSV, . ADO , .

( ASP VBScript):

On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = Server.CreateObject("ADODB.Connection")
Set objRecordSet = Server.CreateObject("ADODB.Recordset")

strPathtoTextFile = server.mappath(".")   'Path to your text file

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=" & strPathtoTextFile & ";" & _
         "Extended Properties=""text;HDR=YES;FMT=Delimited"""

objRecordset.Open "SELECT * FROM test.txt", _
         objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
    Response.Write "ID: " & objRecordset.Fields.Item("ID") & "<br>"
    Response.Write "Text: " & objRecordset.Fields.Item("Text") & "<br>"
    Response.Write "Number: " & objRecordset.Fields.Item("Number") & "<br>"
    objRecordset.MoveNext
Loop

ADO .

script , , ( asp). schema.ini , , :

[test.txt]
Format=Delimited(;)

text.txt , .

+1

:

str = "Some text..." & chr(13)
str = REPLACE(str,VbCrlf,"")

VbCrlf. .

FUNCTION performStringTreatmentRemoveNewLineChar(byval str)

    IF isNull(str) THEN
        str = ""
    END IF
    str = REPLACE(str,VbCrlf,"")
    performStringTreatmentRemoveNewLineChar = TRIM(str)

END FUNCTION

, . .

0

All Articles