Remove quotes during Export to TXT file

Hello,

I have an agent which creates a TXT file from lotus notes document. The output comes like this,

“10SNE1”,“HCM0001”,“”,“Company1”,“A0058397F”,“123”,“123”,“”,“tata”,“F00723996”

I want to remove quotes, and wants an output like this,

10SNE1,HCM0001, ,Company1,A0058397F",123,123, ,tata, F00723996

Any idea how to do that?

Thanks

MS

Here is an agent which I run,

Sub Initialize

Dim bFileOpen As Integer         

Dim FileName As String

Dim fileNum As Integer

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase





Dim view As NotesView

Dim doc As NotesDocument

Set view = db.GetView( "view1" )

'Get the first document

Set doc = view.GetFirstDocument

’ first get an unused file number from the system

fileNum = Freefile()

’ open file for output

Open "C:\Test1.txt" For Output As fileNum 	





Do While Not(doc Is Nothing) 

’ move fields to variables

	out_Firstname = doc.Getitemvalue("firstname") 

	out_Lastname= doc.Getitemvalue("lastname") 

	out_Dealer_Type2= doc.Getitemvalue("Dealer_Type2")

	out_Company = doc.Getitemvalue("company") 

	Out_randomp = doc.Getitemvalue("randomp")

’ write out string

	Write #fileNum, out_Firstname(0),out_Lastname(0),out_Dealer_Type2(0),out_Company(0) ,out_randomp(0)

’ 'Move onto next document in the view

	Set doc = view.GetNextDocument(doc)

Loop



 'Close file and terminate.          

Close fileNum         



Exit Sub

End Sub

Subject: Remove quotes during Export to TXT file

If you have a read through the help entry on the Write # statement it actually states that it encloses strings in quotes when it outputs them to the file, so I don’t think doing any kind of Replace in your script will work as the quotes don’t actually exist until they hit your text file.

Have a look at either using the Print # statement or NotesStream (as Ken suggested).

Emily.

Subject: Remove quotes during Export to TXT file

try the below functionI think it would be called as

atReplaceSubstring(out_Firstname, “"”, “”)

Not sure about removing quotes, it has been a long time since I had to do that

You need all 3 Functions

Function atReplaceSubstring(source As Variant, repl As Variant, replacewith As Variant) As Variant

’ Written 24 Sept 1996 by Andre Guirard.

Dim tTo As Variant, tFrom As Variant

Dim i&, j&

’ If the search string and replacement are not arrays, make them one element arrays; this makes the

’ subsequent code simpler.

If Isarray(repl) Then

	tFrom = repl

Else

	tFrom = SingleElementArray(repl)

End If

If Isarray(replacewith) Then

	tTo = replacewith

Else

	tTo = SingleElementArray(replacewith)

End If

’ If the main input is an array, recursively process each element and return the results as an array.

If Isarray(source) Then

	Redim result(Lbound(source) To Ubound(source)) As Variant

	For i = Lbound(source) To Ubound(source)

		result(i) = atReplaceSubstring(source(i), tFrom, tTo)

	Next

	atReplaceSubstring = result

Else

	Dim res$, src$

	src$ = source

	For i = 1 To Len(src$)

’ Scan the list of search strings to see whether any of them is present at position i in the source string.

		For j = Lbound(tFrom) To Ubound(tFrom)

			If tFrom(j) = Mid$(src$, i, Len(tFrom(j))) Then

				Exit For

			End If

		Next

’ If a match was found, replace it in the output with the corresponding “replacewith” entry.

		If j <= Ubound(tFrom) Then

			res$ = res$ + tTo(min(Ubound(tTo), j))

			i = i + max(0, Len(tFrom(j)) - 1)

’ shift the input pointer past the end of the matching string so we don’t match another string in the middle of it.

		Else

’ Otherwise, copy over the one character at position i.

			res$ = res$ + Mid$(src$, i, 1)

		End If

	Next

	atReplaceSubstring = res$

End If

End Function

Function max(a,b)

If a < b Then

	max = b

Else

	max = a

End If

End Function

Function min(a,b)

If a < b Then

	min = a

Else

	min = b

End If

End Function

Subject: RE: Remove quotes during Export to TXT file

Michael,

There is no need for a homebrewed “ReplaceSubstring” function. Just use the Replace function that comes with LotusScript. It works on both regular strings and string arrays.

Manish,

Do those fields actually contain double quotes in their values? If so, why not eliminate them in the fields before you ever get to your code? If not, then LotusScript may be adding them and stripping them out won’t work. My advice to you is to scrap Write and use NotesStream to create your file. It is much more versatile in what you can write to a file.

Ken

Subject: RE: Remove quotes during Export to TXT file

Ken, picky picky

Subject: You Should Be Thanking Me!

Michael,

I can’t imagine that you would intentionally provide someone with outdated information. Therefore, I stepped in to let you know that LotusScript recently added a new Replace function that accomplishes the same task.

We too have a homebrewed ReplaceSubstring function at the company where I work, and it was necessary, as you found, back when no alternative existed. It still shows up quite a lot in our code, but when I come across our ReplaceSubstring function, I update it to use Replace instead.

Ken

Subject: RE: You Should Be Thanking Me!

Yes I am thanking you now, old habits hard to kill