locked
how to get values from first two paragraphs in vb.net 2.0 RRS feed

  • Question

  • User1312823613 posted

    hi all ,

    i'm using vb.net 2.0. i want to get values from a textbox1's first or second para's . That is if the first para is less that 200 i want to get second para and show the first two para's in the textbox2 other display only the first para's in textbox2. 


    Please tell me how to get these..

    Monday, November 10, 2008 7:22 AM

Answers

  • User1312823613 posted

    Hi,

    Got the Solution :)

     

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox2.Text = GetPara(TextBox1.Text.Trim())
           
    End Sub
    
    Private Function GetPara(ByVal strText As String)
            Dim strTextSplit As String() = strText.Split(vbCrLf)
            Dim Counti As Integer = 0
            Dim strModText As String = ""
            Dim strSpaces As String = ""
            For Each strInArray As String In strTextSplit
                If strInArray.Trim() <> "" And Counti = 0 Then
                    strModText = strInArray
                    Counti = 1
                ElseIf Counti = 1 And strModText.Length < 250 Then
                    If strInArray.Trim() <> "" Then
                        If strSpaces <> "" Then
                            strModText += strSpaces
                        End If
                        strModText += strInArray
                        Counti = 2
                    Else
                        strSpaces += strInArray
                    End If
                End If
            Next strInArray
            Return strModText
    End Function
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 12, 2008 2:33 AM

All replies

  • User-990694832 posted

    Please be a little more clear, the text is confusing.

    sounds like the string needs to be searched for a number of spaces for a location to be split by and then sent to text boxes 

    DK 

    Monday, November 10, 2008 9:01 AM
  • User1312823613 posted

    I'll explain with an example...

    Example 1

    In textbox1 i enter these sentences

    "President-elect Barack Obama and his wife, Michelle, took their first post-election White House tour on Monday, officially setting in motion America's intricate minuet of transition from one President to the next.

    President George W. Bush and First Lady Laura Bush greeted the Obamas, who arrived 11 minutes early on a sunny fall day with moderate temperatures and colorful -- but fading -- autumn leaves.

    The Obamas stepped out of a black limousine, were welcomed by the Bushes and escorted into the Executive Mansion that they'll call home in a little more than two months."

    See the first para length . it is 213. since the first para is less than 250, i want to get the second para also. i.e., in the textbox2 i want to display the sentences

    "President-elect Barack Obama and his wife, Michelle, took their first post-election White House tour on Monday, officially setting in motion America's intricate minuet of transition from one President to the next.

    President George W. Bush and First Lady Laura Bush greeted the Obamas, who arrived 11 minutes early on a sunny fall day with moderate temperatures and colorful -- but fading -- autumn leaves."

    Example 2

    Now if the textbox1 contents is as follows,

    "President-elect Barack Obama and his wife, Michelle, took their first post-election White House tour on Monday, officially setting in motion America's intricate minuet of transition from one President to the next. President George W.Bush and First La

    dy Laura Bush greeted the Obamas, who arrived 11 minutes early on a sunny fall day with moderate temperatures and colorful -- but fading -- autumn leaves.

    The Obamas stepped out of a black limousine, were welcomed by the Bushes and escorted into the Executive Mansion that they'll call home in a little more than two months."

    the first para length is 250 . So i want to display the textbox2 only the first para i.e.,

    "President-elect Barack Obama and his wife, Michelle, took their first post-election White House tour on Monday, officially setting in motion America's intricate minuet of transition from one President to the next. President George W.Bush and First La"

     Hope you got want i said.. Please tell me how to get these...

     

    Monday, November 10, 2008 11:37 PM
  • User1312823613 posted

    Hi,

    Got the Solution :)

     

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox2.Text = GetPara(TextBox1.Text.Trim())
           
    End Sub
    
    Private Function GetPara(ByVal strText As String)
            Dim strTextSplit As String() = strText.Split(vbCrLf)
            Dim Counti As Integer = 0
            Dim strModText As String = ""
            Dim strSpaces As String = ""
            For Each strInArray As String In strTextSplit
                If strInArray.Trim() <> "" And Counti = 0 Then
                    strModText = strInArray
                    Counti = 1
                ElseIf Counti = 1 And strModText.Length < 250 Then
                    If strInArray.Trim() <> "" Then
                        If strSpaces <> "" Then
                            strModText += strSpaces
                        End If
                        strModText += strInArray
                        Counti = 2
                    Else
                        strSpaces += strInArray
                    End If
                End If
            Next strInArray
            Return strModText
    End Function
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 12, 2008 2:33 AM