View Single Post
  #19   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Fast way to truncate string

Hi Robert,

Am Tue, 31 Mar 2015 01:54:51 -0700 schrieb Robert Crandal:

Sub main_test()

Dim sFile1 As String
Dim sFile2 As String
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim vData ' variant

gsBlankLine = Chr(13) & Chr(13) & Chr(10)
sFile1 = "C:\inp.txt"
sFile2 = "C:\out.txt"

'Group directly into chapters divided by "*" borders
vData = Split(ReadTextFile(sFile1), String(80, "*"))

i = FreeFile()

Open sFile2 For Output As #i

' Scan all narratives
For n = LBound(vData) To UBound(vData)

sClean = Split(vData(n), gsBlankLine)
For j = LBound(sClean) To UBound(sClean)

'
' ******** Error occurrs here *********
'
Print #i, TruncateString(sClean(j), "especially so")

Next ' j

Next ' n

Close #i

End Sub


drag vData and sClean into the watch window and step with F8 through
your code.
What about the borders? Are there 20 asterix as in the question before?
Then try:
strSplit = Application.Rept("*", 20)
vData = Split(ReadTextFile(sFile1), String(80,strSplit))


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional