Results 1 to 9 of 9

Thread: [RESOLVED] Retrieve Text from RTB and place in a string array

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Resolved [RESOLVED] Retrieve Text from RTB and place in a string array

    Hi guys,

    So I have found a way to getting text out of an RTB like so:

    VB Code:
    1. Imports System.IO
    2. Imports System.Text
    3.  
    4. Class Window1
    5.  
    6.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
    7.  
    8.         Dim tr As New TextRange(RichTextBox1.Document.ContentStart, RichTextBox1.Document.ContentEnd)
    9.         Dim ms As New MemoryStream
    10.         tr.Save(ms, DataFormats.Text)
    11.         Dim MyArray As String = ASCIIEncoding.Default.GetString(ms.ToArray())
    12.  
    13.  
    14.  
    15.  
    16.     End Sub
    17. End Class

    The issue im having is that the string from the last line only seems to be 1 string I thought it would be an array of strings? It could be my rusty array logic? any idea's?

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Retrieve Text from RTB and place in a string array

    Try this instead:

    vb.net Code:
    1. Dim MyArray() As String = ASCIIEncoding.Default.GetString(ms.ToArray())

    Notice the () after MyArray
    Last edited by chris128; Jan 27th, 2009 at 07:58 AM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Retrieve Text from RTB and place in a string array

    I tried that, I get everything after the = highlighted blue and the error 'value of the type string cannot be converted to 1 dimensional Array of string. hmm it seems I may have to pick out each item of the flow document individually!

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Retrieve Text from RTB and place in a string array

    Actually no sorry ignore that, I didnt properly look at what you were doing. Your calling the GetString method right? Well that just returns one string, not an array of strings.
    Do you need it to be an array for some reason? Like an item in the array for every line in the RTB? If you wanted to get separate lines in the RTB you could do this:
    Code:
    Dim MyArray() As String = ASCIIEncoding.Default.GetString(ms.ToArray).Split(vbNewLine)
    Obviously that wont count lines that are just wordwrapped onto the next line, it will just split the text using the new line character
    Last edited by chris128; Jan 27th, 2009 at 08:06 AM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Retrieve Text from RTB and place in a string array

    Just seen your last post, I'm afraid I dont know much about FlowDocuments yet so probably cant help, but if you can explain exactly what you have and what your doing I can try
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Retrieve Text from RTB and place in a string array

    That's exactly what I need your a legend chris, wow my VB is very rusty. As to why I need it well processing Xaml for highlighting is easier done on a string by string basis.

  7. #7
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Retrieve Text from RTB and place in a string array

    haha no worries
    Now be a good boy and mark the thread as resolved :P
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: [RESOLVED] Retrieve Text from RTB and place in a string array

    Done, I dont suppose you want to learn about regex and then do all my expression for me? no, oh ok

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] Retrieve Text from RTB and place in a string array

    Nah I hate regex!

    Well I like it, but I'm no good at it
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width