Results 1 to 3 of 3

Thread: Remove new line from vbscript

  1. #1
    Join Date
    Feb 2009
    Posts
    20

    Remove new line from vbscript

    Hi GUys,

    From my vbs code it write the empty next line which i don't want it. Appreciate any of yours can see my code if there is a syntax ERROR that creating a new next line when i write into .csv file

    book.cvs file example:
    DN,name,title,office
    "CN=th, DC=dsa, MY=jsda",yew,VP,raja laut
    "CN=th1, DC=dsa, MY=jsda",yew1,VP,raja laut
    "CN=th2, DC=dsa, MY=jsda",yew2,VP,raja laut
    "CN=th3, DC=dsa, MY=jsda",yew3,VP,raja laut
    "CN=th, DC=dsa, MY=jsda",yew,VP,raja laut

    Result I get is below but i dont want a empty line space at each line:
    name,title,office
    yew,VP,raja laut

    yew1,VP,raja laut

    yew2,VP,raja laut

    yew3,VP,raja laut

    yew,VP,raja laut


    My code example:
    Dim objFSO, dataArray, clippedArray1(), clippedArray2()
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Create an array out of the CSV
    'open the data file
    Set oTextStream = objFSO.OpenTextFile("C:\book.csv")
    Set newFile = objFSO.CreateTextFile("C:\newCSV.csv")
    'make an array from the data file
    dataArray = Split(oTextStream.ReadAll, vbNewLine)
    'close the data file
    oTextStream.Close

    x = 0
    For Each strLine In dataArray
    'Get first character
    Call FirstAlign()
    Next

    Function FirstAlign()
    'Now make an array from each line of dataArray
    ReDim Preserve clippedArray1(x)
    clippedArray1(x) = Split(strLine,",")
    CutColumn = 0
    intCount = 0
    newLine = ""
    For Each Element1 In clippedArray1(x)
    If intCount = UBound(clippedArray1(x)) Then
    EndChar = vbCrLf
    Else
    EndChar = ","
    End If

    If intCount <> CutColumn Then
    newLine = newLine & Element1 & EndChar
    End If

    intCount = intCount + 1
    If intCount = UBound(clippedArray1(x))+1 Then
    'Before write into a line check and do second filtering of first Column
    IntCheck = InStr(newLine, chr(34))
    If IntCheck <> 0 Then
    Call SecondAlign(newLine)
    Else
    newFile.Write newLine
    End If
    End If
    Next
    End Function


    Function SecondAlign(strLine2)
    ReDim Preserve clippedArray2(x)
    clippedArray2(x) = Split(strLine2,chr(34))
    CutCol = 0
    intCnt = 0
    secLine = ""
    For Each Element2 In clippedArray2(x)
    If intCnt = UBound(clippedArray2(x)) Then
    EndChar2 = vbCrLf
    Else
    EndChar2 = ","
    End If

    If intCnt <> CutCol Then
    secLine = secLine & Element2 & EndChar2
    End If

    intCnt = intCnt + 1
    If intCnt = UBound(clippedArray2(x))+1 Then
    secLine = Mid(secLine, 2, Len(secLine))
    newFile.Write secLine
    End If
    Next
    End Function

  2. #2
    Join Date
    May 2008
    Posts
    945

    Re: Remove new line from vbscript

    dataArray = Split(oTextStream.ReadAll, vbNewLine)
    and
    EndChar = vbCrLf
    I suppose don't use vbNewLine and vbCrLf because they both will feed that output with the new line (which is your problem). Since you are using both, the output that you are getting have extra lines. I hope I was clear.

  3. #3
    Join Date
    Feb 2009
    Posts
    20

    Re: Remove new line from vbscript

    Quote Originally Posted by Lemog View Post
    and


    I suppose don't use vbNewLine and vbCrLf because they both will feed that output with the new line (which is your problem). Since you are using both, the output that you are getting have extra lines. I hope I was clear.

    Thank you Lemog,
    It resolved by replacing EndChar = "". Good Job

Similar Threads

  1. How to remove black horizontal line in openoffice
    By Efrosini in forum Windows Software
    Replies: 3
    Last Post: 17-02-2012, 04:55 PM
  2. How to create ZIP Files from Command-Line via VBScript?
    By FB in forum Windows Server Help
    Replies: 10
    Last Post: 22-12-2011, 12:18 AM
  3. How to remove leading whitespace from each line?
    By Conraad in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 10:14 PM
  4. How to remove the blank line in excel?
    By Rup_me in forum Windows Software
    Replies: 5
    Last Post: 16-12-2009, 06:48 PM
  5. How can I add a new line to vbscript?
    By Baani in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 04:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,257,948.93000 seconds with 16 queries