Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How To Select and get Text or word or paragraph between two empty lines in textbox winform C#?

this i want

Paragraph one
Paragraph one
Paragraph one

Paragraph two
Paragraph two
Paragraph two


if any two paragraph, select paragraph one when i click paragraph one, but paragraph two not select. any solution?

Thanks For Help!
Posted
Updated 1-Jun-15 3:03am
v4
Comments
Sergey Alexandrovich Kryukov 31-May-15 22:55pm    
What have you tried so far?
Anyway, it's obvious that the problem may have more than one solution (not the ways to solve it, but different solutions: the could be more than one different selections matching this criterion).
—SA
nofry 31-May-15 23:18pm    
I already use
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.Text.Length;

this i want

if any two paragraph, select paragraph one when i click paragraph one, but paragraph two not select. any solution!
Sergey Alexandrovich Kryukov 1-Jun-15 11:14am    
The "paragraph" is the fragment of text between end-of-line characters. On Windows, this is CR LF...
Use it to find out them.
—SA
Abhipal Singh 1-Jun-15 12:55pm    
Open your file in notepad++ to see the newline characters as -SA suggested {CR}{LF}.

Hint: You will need to do a string.Split('your new paragraph char')[0] or string.Split('your new paragraph char').[1]

1 solution

I think you got enough hints in the comments to the question.

You already know how to control selection with SelectionStart and SelectionLength. You also can use this: https://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.110%29.aspx[^].

The final problem is what to use for end-of-line characters. Unfortunately, they are platform-dependent: http://en.wikipedia.org/wiki/Newline[^].

So, you need to use this property: https://msdn.microsoft.com/en-us/library/system.environment.newline%28v=vs.110%29.aspx[^].

Now you know everything to solve the problem. Now, it's your turn.

—SA
 
Share this answer
 
Comments
Maciej Los 1-Jun-15 14:46pm    
5ed!
Sergey Alexandrovich Kryukov 1-Jun-15 14:47pm    
Thank you, Maciej.
—SA

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