|
-
Jul 20th, 2007, 09:16 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Line limit.
well i'm trying to make a textbox multiline with a limit of 39 chars per line.
the divison is made with the conditions of:
-if the line have a space it divides with the first space.
-if the line dont have spaces it put a "-" and it pass to the next line.
the problem is that i'm not reaching the result i whant :S
my code:
vb.net Code:
Public Function Check_text()
Dim myLines As New List(Of String)
Dim letra As String
For Each ln As String In Me.TextBox1.Lines
If ln.Length > 39 Then
Dim revtext As String = ReverseString(ln.Substring(0, 38).ToString)
Dim pos As Integer
pos = InStr(1, revtext, " ")
If pos > 0 Then
' We found it.
TargetPosition = pos
Dim before = revtext.Substring(0, pos + 1).ToString
Dim antes = revtext.Substring(pos, ln.Length - pos - 2).ToString
Mid(revtext, pos, 1) = ""
myLines.Add(ReverseString(antes))
myLines.Add(ReverseString(before))
Else
letra = ln.Substring(38, 1).ToString
myLines.Add(ln.Substring(0, 38) & "-")
myLines.Add(letra & ln.Substring(39))
End If
Else
myLines.Add(ln)
End If
Next
Me.TextBox1.Clear()
Me.TextBox1.Lines = myLines.ToArray
Me.TextBox1.SelectionStart = Me.TextBox1.Text.Length
Check_text = True
End Function
ty if you could help
The Future Is Always The Way To Live The Life
-
Jul 20th, 2007, 09:40 AM
#2
Thread Starter
Hyperactive Member
Re: [2005] Line limit.
bump someone knows how to helP?? :S i real need this :S
The Future Is Always The Way To Live The Life
-
Jul 20th, 2007, 09:44 AM
#3
Re: [2005] Line limit.
You need to be clearer gooden about what the problem actually is... When you say "I'm not reaching the result I want" - it's not very helpful. What does that mean?? Give an example and I'll try and help.
Also, what's the ReverseString bit? Is that a function or something. I don't know if I've seen it in .NET. And why do you reverse it and then re-reverse it to add it? I'm a little confused.
-
Jul 20th, 2007, 09:47 AM
#4
Re: [2005] Line limit.
Are we on a Service Level Agreement here that I wasn't aware of? All posts must be answered within 24 minutes?
-
Jul 20th, 2007, 09:51 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Line limit.
sorry for that jmcilhinney but im a little nervose :S and sorrry for what i did :S
im going to explain. i use the reverse because the space that it have to be divided on the text is the last space. so i reverse i get the first space and do the operaction. the problem is that variavel "before" and the "antes" is giving me worng :S
the before is what comes Antes <- "Space" -> before
ps: i know that is not before and it is after :S if you test the code you will see the error :S
The Future Is Always The Way To Live The Life
-
Jul 20th, 2007, 10:11 AM
#6
Re: [2005] Line limit.
There's a much easier way of doing that then without having to reverse the string.
vb Code:
Dim pos As Integer = ln.LastIndexOf(" "c)
which will give you the last index of a space. Then you check for the value of pos, so it would be something along the lines of (roughly):
vb Code:
If pos <> -1 Then 'Space found:
Dim firstPart As String = ln.Substring(0, pos) 'Get from 1st char up until space
Dim secondPart As String = ln.Substring(pos + 1) 'Get text that appears after space
myLines.Add(firstPart) 'Add to Lines
myLines.Add(secondPart)
edit - Ooops, yes, changed it to pos as it should have been
Last edited by stimbo; Jul 20th, 2007 at 10:19 AM.
-
Jul 20th, 2007, 10:12 AM
#7
Hyperactive Member
Re: [2005] Line limit.
This isn't the best nor cleaniest. Give it a try and see if it does what you want.
vb Code:
Public Function Check_text()
Dim lines() As String = TextBox1.Lines
Dim checkLines As String
Dim LeftOverLine As String
Dim x As Integer
TextBox1.Clear()
For x = 0 To lines.Length - 1
If lines(x).Length > 39 Then
checkLines = lines(x).ToString.Substring(0, 38)
If InStrRev(checkLines, " ") Then
checkLines = Mid(checkLines, 1, InStrRev(checkLines, " "))
LeftOverLine = lines(x).ToString.Substring(checkLines.Length, lines(x).ToString.Length - checkLines.Length)
TextBox1.AppendText(checkLines & vbNewLine & LeftOverLine & vbNewLine)
Else
LeftOverLine = lines(x).ToString.Substring(checkLines.Length, lines(x).ToString.Length - checkLines.Length)
TextBox1.AppendText(checkLines & "-" & vbNewLine & LeftOverLine & vbNewLine)
End If
End If
Next
Return True
End Function
-
Jul 20th, 2007, 10:14 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] Line limit.
 Originally Posted by stimbo
There's a much easier way of doing that then without having to reverse the string.
vb Code:
Dim pos As Integer = ln.LastIndexOf(" "c)
which will give you the last index of a space. Then you check for the value of pos, so it would be something along the lines of (roughly):
vb Code:
If pos <> -1 Then 'Space found:
Dim firstPart As String = ln.Substring(0, findSpace) 'Get from 1st char up until space
Dim secondPart As String = ln.Substring(findSpace + 1) 'Get text that appears after space
myLines.Add(firstPart) 'Add to Lines
myLines.Add(secondPart)
that findspace is the pos???
edited:
I put the pos and worked Ty very much and sorry for what i did :S
The Future Is Always The Way To Live The Life
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|