Solved

Break at word only and indent

Posted on 2004-04-26
9
189 Views
Last Modified: 2010-04-17
here's my code to break my string before the end of the page...

      Do
         Select Case Len(strT1)
            Case Is <= 90
               strT2 = strT1
               strT1 = ""
            Case Is > 90
               strT2 = Left(strT1, 90)
               strT1 = Trim(Mid(strT1, 91))
         End Select
         intReg = intReg + 1
         SetRegString intReg, strT2

      Loop Until Len(strT1) = 0

It works fine, but I need it to only break where there is a space, further, indent the second line by let's say 10 spaces...that should be easy, just add a blank string to strT2.
0
Comment
Question by:lexo
  • 3
  • 3
9 Comments
 
LVL 14

Expert Comment

by:wayside
Comment Utility
How about this:

      Do
         Select Case Len(strT1)
            Case Is <= 90
               strT2 = strT1
               strT1 = ""
            Case Is > 90
               strT2 = Left(strT1, 90)
 
               whereIsSpace = strT2.LastIndexOf(" ")
               If whereIsSpace <> -1 Then
                    strT2 = Left(strT1, whereIsSpace);
                    strT1 = "          " & Trim(Mid(strT1, whereIsSpace))
               Else
                    strT1 = "          " & Trim(Mid(strT1, 91))
               End If

         End Select
         intReg = intReg + 1
         SetRegString intReg, strT2

      Loop Until Len(strT1) = 0

0
 

Author Comment

by:lexo
Comment Utility
I am using ghetto Sax Basic, I don't think there is a function called WhereIsSpace.  Got another suggestion?
0
 
LVL 14

Expert Comment

by:wayside
Comment Utility
The relevant function is LastIndexOf(), whereIsSpace is an integer that holds the index of the last space.

The algorithm is this:

1) cut the original string at 90 characters:  Left (str, 90)
2) search from the end of the 90 characters until you find a space; now you know how many characters it is until the first space.
3) cut the original string at however many characters it is to the first space
4) get second string by using Mid() function, starting where the first space is. Add 10 spaces at the beginning.

I don't know ghetto Sax Basic, so I don't know exactly what the string manipulation functions are. Visual Basic has a functions called LastIndexOf() which searches a string from the back; maybe your Basic has an equivalent. If not you could always check backwards from character 90 one character at a time in a loop until you find a space.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:lexo
Comment Utility
Yes, I undersand all of this, I posted the code I wrote and I know what it does.  I think what you are trying to say is that I need to declare wherespaceis as a string.  So the real problem is that Sax Basic does not have LastIndexOf() as a function.  Do you know a of a way to get around this?
0
 
LVL 19

Expert Comment

by:dakyd
Comment Utility
if Sax Basic supports the indexOf function, you can replace this line:
whereIsSpace = strT2.LastIndexOf(" ")

with:
whereIsSpace = -1
Do While strT2.indexOf(" ", whereIsSpace + 1) > -1
  whereIsSpace = strT2.indexOf(" ", whereIsSpace + 1)
Loop

Hope that helps.
0
 
LVL 14

Accepted Solution

by:
wayside earned 250 total points
Comment Utility
The Visual Basic LastIndexOf() function returns an int, which is the character index of the string where the character is.

Dim whereIsSpace as Integer;
whereIsSpace = strT2.LastIndexOf(" ");

whereIsSpace will be something like 87 or 83 or whatever.

Then you can use this number in the Left() and Mid() functions to break the original string on the space.

strT2 = Left(strT1, whereIsSpace);
strT1 = Mid(strT1, whereIsSpace);

You could write your own LastIndexOf function:

Sub LastIndexOf(strToSearch, charToFund, indexOfLastSpace)
bNotFound = TRUE

indexOfLastSpace = Len(strToSearch)-1
Do While bNotFound
   If strToSearch.Char(indexOfLastSpace) = charToFind Then
       bNotFound = FALSE  
   Else
       indexOfLastSpace = indexOfLastSpace - 1
   End If
Loop
End Sub

and call it like this:

Dim whereIsSpace as Integer
Dim spaceChar as Char
spaceChar = ' '

' sets whereIsSpace to -1 if space is not found, otherwise sets it
' to the index of the space character
whereIsSpace = LastIndexOf(strT1, spaceChar, whereIsSpace)

This is Visual Basic, though, you will have to implement based on your version of Basic.
0
 

Author Comment

by:lexo
Comment Utility
Can you go over the proper steps to declare the function?  I am unfamiliar with this.
Thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to adjust sheet 1 81
userCompare  challenge 3 61
wordappend challenge 8 84
PHP question(s) about order of output 9 39
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now