Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how do i split sentence and put on two textboxes without split any words
as if i dived NINETEEN THOUSAND THREE HUNDRED FORTY FIVE RUPEES ONLY in two textbox without divide the any words

i want NINETEEN THOUSAND THREE HUNDRED FORTY in first textbox and FIVE RUPEES ONLY in second textbox but not divide any word like FOURTY IN FOU RTY.

I tried this code but it split the words
VB
Dim len As Integer = Me.TextBox1.Text.Trim.Length()
        If len > 25 Then
            Me.TextBox2.Text = Me.TextBox1.Text.Substring(0, 24)
            Me.TextBox3.Text = Me.TextBox1.Text.Substring(24, len - 24)

        Else
            Me.TextBox2.Text = Me.TextBox1.Text.Trim
        End If



Edited/ Typo
Posted
Updated 12-Mar-15 20:28pm
v5
Comments
King Fisher 13-Mar-15 2:20am    
Have you tried anything ?
King Fisher 13-Mar-15 2:27am    
you can't split the words with out any logic.
but Is it okay NINETEEN THOUSAND THREE HUNDRED FORTY FIVE in First Text Box and RUPEES ONLY in second textbox ?
Santosh K. Tripathi 13-Mar-15 2:34am    
what do you want to show in each boxes if you have like this

1. NINETEEN THOUSAND THREE HUNDRED FORTY RUPEES ONLY
2. NINETEEN THOUSAND THREE HUNDRED FIVE RUPEES ONLY
3. NINETEEN THOUSAND FORTY FIVE RUPEES ONLY
4. NINETEEN THOUSAND FIVE RUPEES ONLY
5. FORTY FIVE RUPEES ONLY
6. FIVE RUPEES ONLY
and so on...

what are rules to show text to show in each boxes?
Maciej Los 13-Mar-15 2:48am    
Use UI controls properties instead of "spliting" text on unknown criteria.

1 solution

well it seems you try to split the words it the value is greater than 25 characters,
here is the logic as per your code
VB
Dim spacepos As Integer = 0
spacepos = Me.TextBox1.Text.LastIndexOf(" ", 25)
Me.TextBox2.Text = Me.TextBox1.Text.Substring(0, spacepos)
Me.TextBox3.Text = Me.TextBox1.Text.Substring(spacepos + 1, len - spacepos - 1)
MessageBox.Show(Me.TextBox2.Text.Length())
MessageBox.Show(Me.TextBox3.Text.Length())

but it seems the second textbox has more than 25 characters if the above logic is okay then don't read the below one

VB
Dim tempstring As String = Me.TextBox1.Text
While tempstring.Length > 25
    spacepos = tempstring.LastIndexOf(" ", 25)
    MessageBox.Show(tempstring.Substring(0, spacepos))
    tempstring = tempstring.Substring(spacepos + 1, tempstring.Length - spacepos - 1)
End While
MessageBox.Show(tempstring)


the above code splits all the word for 25 characters and below
 
Share this answer
 
Comments
SoftEngAshu 13-Mar-15 7:45am    
Thanks Thava Rajan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900