Searching RichTextBox and deleting all between - richtextbox

I'm having a little trouble trying to figure out how to search all the text in my RichTextBox and delete everything between the parentheses (including the parentheses). I have a lot of files with different comments wrote in the parentheses that may have different text in them.
Example : This is my text in the text box (AS YOU CAN SEE HERE). I am wanting to be able to read the entire text box (This would be another comment) and delete the out.
Result: This is my text in the text box. I am wanting to be able to read the entire text box and delete the out.
The rich text box are usually longer files than just a couple lines. Any help would be gratefully appreciated.

You can use a regular expression for this:
Regex r = new Regex("\(.+?\)");
If you are using a richtextbox or a textbox:
rtb.Text = r.Replace(rtb.Text,"");
You can do this without reading the file into the richttextbox:
string filetext = File.ReadAllText("file.txt");
filetext = r.Replace(filetext,"");
File.WriteAllText("file.txt",filetext);
Or in one line:
File.WriteAllText("file.txt",r.Replace(File.ReadAllText("file.txt"),""));
You can loop all files in a directory:
foreach(string file in Directory.GetFiles(targetDirectory)
File.WriteAllText(file,r.Replace(File.ReadAllText(file),""));

Related

Dynamic hyperlink with mergefield possible?

I've tried several guides, but i haven't really found that any of them fit my purpose.
The problem seems simple enough, i want to create a dynamic link based on a variable.
I've tried inserting a Hyperlink with temp text and link, replacing the text within the "" brackets, with a MergeField corresponding to the variable.
Whenever i test it, the variable does not register. The syntax is as follows :
{ HYPERLINK "www.staticurl/{MergeField varurl}" }
Does anyone have any suggestions on why this variable does not register?
Thanks in advance!

Output (Display) a random chosen piece of text from a bigger list of text - Ruby On Rails

I want to output a couple of lines of text from a bigger list of text saved as a .txt file and and I want it to randomly output itself into a selected div upon refreshing or simply arriving at a webpage. Do any of you "gurus" out there have some idea on how to do something like or similar to this.
Thank you.
You could use the readlines method of IO:
array_of_each_lines = IO.readlines('filename.txt')
random_line = rand(array_of_each_lines.size)
my_random_line_as_string = array_of_each_lines[random_line]

ABCPdf .EmbedFont not working when adding Russian (Cyrillic) text

We use ABCpdf software, and recently added a Russian translation option for some of our documents. Most of the contents of the PDF come from a web page using the AddImageURL method. This all works fine, meaning that the Russian text is readable.
However, we have a few text sections that need to be placed exactly at the bottom of the page, so we do this with ABCpdf's AddText method. These strings show up as ???????? in the generated PDF.
Here's a quick code sample:
Doc pdfDoc = new Doc();
//snip snip snip...
//add footer text
pdfDoc.Rect.SetRect(30, 30, 552, 10); //footer section
pdfDoc.HPos = 0; //set horizontal position to left
pdfDoc.AddText(GetRussianString("REFERENCE") + " #" + ReferenceID);
After reading the documentation on Websupergoo's site, I tried using AddFont and EmbedFont (separately and together), but this did not work:
pdfDoc.Font = pdfDoc.EmbedFont("Times-Roman", LanguageType.Unicode);
I also searched for ways to set encoding at the document level, and didn't find any documentation on this, at least not for version 8. We are currently using 8.11.2 of the ABCpdf software.
Has anybody done something like this successfully?
OK, the (totally embarrassing) answer is that I was being far too literal about the example from WebSuperGoo's site. I needed to use the exact font name from my development/production machine.
pdfDoc.Font = pdfDoc.EmbedFont("Times New Roman", LanguageType.Unicode);
Obvious? Yes. But it's one of things that can be overlooked when in a hurry, so I'll post the answer here in case anybody else gets tripped up.
Part of my confusion stemmed from the fact that Russian text added from a URL was just fine in the document, but not the content added as text. I'm guessing that abcPDF sets the font according to the encoding it gets from the web page, but that affects only the content it is pulling in, not the overall PDF.
Anyhow, thanks to gekannt and anybody else who took a look.

Extraction from string - Ruby

I have a string. That string is a html code and it serves as a teaser for the blog posts I am creating. The whole html code (teaser) is stored in a field in the database.
My goal: I'd like to make that when a user (facebook like social button) likes certain blog post, right data is displayed on his news feeds. In order to do that I need to extract from the teaser in the first occurrence of an image an image path inside src="i-m-a-g-e--p-a-t-h". I succeeded when a user puts only one image in teaser, but if he accidentally puts two images or more the whole thing craches.
Furthermore, for description field I need to extract text inside the first occurrence inside <p> tag. The problem is also that a user can put an image inside the first tag.
I would very much appreciate if an expert could help me resolve this what's been bugging me for days.
Text string with a regular expression for extracting src can be found here: http://rubular.com/r/gajzivoBSf
Thanks!
Don't try to parse HTML by yourself. Let the professionals do it.
require 'nokogiri'
frag = Nokogiri::HTML.fragment( your_html_string )
first_img_src = frag.at_css('img')['src']
first_p_text = frag.at_css('p').text

extract text from word or pdf based on format (font name and size)

I need to parse large text (about 1000 pages of word or pdf document)and place some of the text inside this document into database fields
I found that the only thing I can distinguish the text I want to extract is the format , it is always "Helvetica-Condensed" size 12
can I do that ? I know how to use the string functions but what I should use to test the format ?
as I said the text is stored inside word document or PDF
if there is third party component can do no problem please refer it to me
Thanks
There is QuickPDF. The price is $249,00.
The other option is to code it yourself. The file specification is available online, and if your only trying to rip the text out of the document this should guide you most of the way.
The only thing to be careful of are documents which are built entirely from images. In that scenario (no matter what you use to read the file) you will also need an OCR type of application. To see if this is the case or not, open a sample of the type of file you are wanting to "extract" text from, select the text to copy then try to paste into notepad.

Resources