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 :thumbup1:
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
Re: Remove new line from vbscript
Quote:
dataArray = Split(oTextStream.ReadAll, vbNewLine)
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.
Re: Remove new line from vbscript
Quote:
Originally Posted by
Lemog
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 :thumbup1: