-
Rich text box in WPF
Hey,
I want to read every line out of a WPF richtextbox. I have the following code, but don't know how to proceed:
Code:
string rtbContents = new TextRange(rtbPaths.Document.ContentStart, rtbPaths.Document.ContentEnd).Text;
foreach (string line in rtbContents.Split(/* new line */))
{
// Do something with every line that is not empty after trim
}
How do I split on a return? (In vb winforms you have control keys, but I can't find it in a c# wpf app.)
How do I trim the lines (and also remove the \r and other things)?
Cheers
BN
-
Try this:
Code:
string rtbContents = new TextRange(rtbPaths.Document.ContentStart,
rtbPaths.Document.ContentEnd).Text;
foreach (string line in rtbContents.Split('\n'))
{
if (line.Trim(' ', '\r').Length != 0)
{
// Do something with every line that is not empty after trim
}
}
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Ok, thnx a lot! Got it working. This is how I implemented it:
Code:
string rtbContents = new TextRange(rtbPaths.Document.ContentStart, rtbPaths.Document.ContentEnd).Text;
foreach (string line in rtbContents.Split('\n'))
{
String trimmedLine = line.Trim(' ', '\r');
if (trimmedLine.Length > 0)
{
downloader.Files.Add(new FileDownloader.FileInfo(trimmedLine));
}
}
I'm curious, is there a way in WPF to have a simple multi line text box without layout ect? I've messed around with textbox and textarea a little but didn't manage to achieve this.
Cheers
BN
Similar Threads
-
By wisgro in forum VB Classic
Replies: 7
Last Post: 09-14-2008, 07:06 AM
-
By GermanD in forum VB Classic
Replies: 10
Last Post: 05-25-2005, 01:44 PM
-
By Sean Woods in forum VB Classic
Replies: 0
Last Post: 02-04-2002, 07:31 PM
-
By Mike Sharp in forum VB Classic
Replies: 0
Last Post: 07-26-2001, 06:10 AM
-
By Javaid Ahmad in forum VB Classic
Replies: 2
Last Post: 04-18-2000, 05:44 AM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|