String Manipulation

  • Thread starter Thread starter Kirk Bay
  • Start date Start date
K

Kirk Bay

I'm trying to build an app that populates a word form. The problem
I've got is when the user types more data than the field will hold, I
need to take the excess and dump it onto a continuation page. The
string I'm dealing with is an undetermined length and can have several
carriage returns in it. Each line can be 75 characters long, so my
thinking was to go through the string until I get to a CR or the first
space before 75 characters and call that a line and put in a CR if
necessary.

Any thoughts on the best way to do this. I thought I had all laid out
in my mind, but you now how that goes.

Thanks

Kirk
 
Hi Kirk,

Some questions.

1 Is there a limit for the number of characters in the entire field?
2 Is there a limit on the number of lines per field?
3 Is there a limit on the number of characters per line?
4 Do you want to preserve lines or is it ok, as you seem to be
suggesting, to split a line.
5 If splitting is ok, are we talking word-wrap where the excess on one
line is joined to the text on the next?
6 Is there the same limitation on continuation pages, meaning that
they'll need to be split too?

Regards,
Fergus
 
1. There is no limit on the amount text.
2. Yep. 10 lines or so. Regardless of the count, I'm going to want to
keep track of how many lines so I can change if necessary.
3. Because it's a word document, I guess there's technically not a limit
on the number of characters per line, but my thinking is to put a CR at
the first space prior to 75.
4. Lines don't necessarily have to be preserved. Like I mentioned above,
I'm thinking about putting a CR at the end of everyline whether it's
going to wrap or not.
5. See above.
6. Continuation pages will be just like a "normal" document, word wrap
and all.

Kirk
 
Hi Kirk,

Just so that I understand, is this a correct abstract restatement of your
problem ?

Given a single string of arbitrary length, optionally containing
line-breaks, break this up into groups of lines (initially 10 per group but
this is arbitrary). Each line will be less than or equal to an arbitrary
maximum length (initially 75 characters) and broken at the nearest space to
that limit.

If so, one method would be to create the lines one at a time in an
ArrayList. Leave the original string untouched and just take sections out as
required (ie, don't remove the line and start at the beginning but keep an
index into the string. This will save on string allocations and the copying of
text, expecially if the text is large.) Then you can apportion the lines to
your field and continuation pages as required in a second phase.

Is this what you had in mind? Or were you hoiping for more choices, or
more details, perhaps, on the splitting, etc?

Regards,
Fergus
 
This seems to work:

Dim thisColl As Queue = New Queue()
Dim newString As String
Try
Do While inputStr.Length > 0
If inputStr.Substring(0,
inputStr.IndexOf(Chr(13))).Length < 70 _
Or inputStr.Substring(0,
inputStr.IndexOf(Microsoft.VisualBasic.Right(inputStr, 1))).Length < 70
_
Then
newString = inputStr.Substring(0,
inputStr.IndexOf(Chr(13)) + 1)
Else
newString = inputStr.Substring(0, 70)
End If

thisColl.Enqueue(newString)
inputStr = inputStr.Remove(0, newString.Length)
Loop
Catch exc As Exception
thisColl.Enqueue(inputStr)
End Try
Dim colCtr As Integer = thisColl.Count - 4
Do While thisColl.Count > colCtr
newString = newString & thisColl.Dequeue
Loop

Return newString
 
Back
Top