Multiple occurrence of regular expression in a multiline textbox - c#

I am developing a windows application using c#. I am loading a file (html, txt, xhtml) to the text box. I want to test the occurrence of following cases in my text box.
,(comma) with closeup text (ex. text1,text2)
.(dot) with closeup text (ex. text1.text2)
:(colon) with closeup text (ex. text1:text2)
,(comma) with closeup ' i.e (left single quotation mark)
"(doublequote) with closeup text
'(single quote) with closeup text
</i> with closeup text (ex. </i>text)
</span> with closeup text.
For all the occurrences of the above condition I want to highlight the particular found text in the textbox. I am trying to use the regular expression. I am inserting all the cases in the array list and checking one by one. For the first case if the text in the textbox is like hjhdf, dfsjf then it will show the message box, if any text before and after this particular text then it will not show the messagebox.
string regexerror = wordToFind;
Regex myregex = new Regex("^[,]*[a-zA-Z]*$");
bool isexist = myregex.IsMatch(rtbFileDisplay.Text);
if (isexist)
{
MessageBox.Show("Hi");
}

At the moment you're only matching the beginning of the entire text with ^. You need to get it to match the beginning of a line instead.
Look at this link: http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx. This explains use of the MultiLine property:
myregex.MultLine=true;
This should do the job.

Related

How to bold a part of string being passed into TextBox in c#

I have a string builder where value is appending at runtime via placeholder. Once string builder has appended, it is assigned to a text box (not rich txt) to show up in UI.
I want part of the text to be bold.
sb.AppendFormat("Added {0} by {1}:\n{2}", DateTime.ToString(), userName, note);
txt.Text = sb.ToString();
Expected output:
Added 9/01/2016 8:47:19 PM by Vinoth: Testing Purpose
How can I achieve this? Is there anyway of looping over words with the : symbol until I want it to be bold?
You will have to build up the text in sections.
Either as different TextBoxes/TextBlocks or as a single RichTextBox with separate Runs for the sections you want in a different style.

making some words bold in textbox winform

Maybe some of you can help me with the following problem. I want some words bolded in a textbox(winforms).
I have a string _descripton variable containing some description text. For example:
“ this is a description of a \b car \b0………… ”. Im trying to replace the string format with richtextformat like:
string _makebold = _description.Replace("\b", #"{\rtf1\ansi \b").Replace("\b0", " \b0.}");
to get the following result: this is a description of a #"{\rtf1\ansi \b car\b0.}"……….
And finally setting the text property of the richtextbox1:
richTextBox1.Text = _makebold;
I cant get that specific word bolded in a richTextbox and textbox doenst work either.
can anyone help me with a solution?
Thanks!
You can use Rtf property of the rich text box control.
For example, the following text adds the text "This text is in bold." to an existing RichTextBox control.
See this MSDN link.
richTextBox1.Rtf = #"{\rtf1\ansi This is in \b bold\b0.}";

Over come placeholder text with innerText

What I want to do is to fill it with text programatically.
webBrowser1.Document.GetElementById("textBox").InnerText = "foo";
This code works but some websites have a placeholder text. This code will not allow me to fill this as value but instead it as a placeholder text.
Strangely in some text box, it will be paste as value when there are a placeholder text. But some text box it wont.
Another scenario is that when it is innerText is placed as a placeholder text, all I have to do is click on that text box and write something next to it. This will act as a text box values.
Is there another way around this?
You need to set the value attribute of the <input id='textBox'> elment not the innertext.
webBrowser1.Document.GetElementById("textBox").SetAttribute("value", "text text text");

text with quotes in html textbox

I have a text box on an html form that I set with a value from the server. But if the value contains an quotation mark, it breaks things. So I html encode it to produce the quote entity, but now this entity shows up in the text box on the page.

How to Make a Text Box Equal All Letters To The Left of a Specific Letter or Character From Another Text Box in C#

I am trying to figure out a simple way of making a text box equal all letters to the left of a "-" in another text box. Basically, if an end-user types blah-test in textbox1, I would like textbox2 to equal blah. I have tried if statements and substrings based off of letter position count (i.e. substring(0, 5); however, this got very lengthy and impractical, since the words entered into textbox1 can be any length.
Thank you,
DFM
Try this:
if(textbox2.text.Contains("-"))
{
textbox1.text = textbox2.text.Split("-")[0];
}
Here we first check if textbox2 contains the - character and if it does we split the text in two parts and set the text of textbox1 to the part that is left of the first - character.
it's very simple
select and double click on the OnTextChange event on textbox1
Write this code inside textbox1_OnTextChange:
string text = textbox1.Text;
textbox2.text = text.Substring(0, text.indexOf("-"));
and you're done!

Categories

Resources