How to make some words bold in a given text file through the program?
Printable View
How to make some words bold in a given text file through the program?
Well, that depends on the format of the file.
Text (as in, one long string) by itself doesn't have any font-related properties, it's just character data.
Now, different applications use different file formats. Take HTML for example: HTML, used to represent web pages, is just plain text, with some special tags that carry metadata about the text data itself. These tags are called markup, and the browser uses them to figure out how to print the given text.
For example, this:
prints as:HTML Code:There is a <b>bold</b> word in this sentence.
There is a bold word in this sentence.
Then, take the forums here: a language similar to HTML is used to markup the text here. When I simulated the HTML output above, I actually typed in this.
The Rich Text Format (RTF) uses a different notation:Code:There is a [B]bold[/B] word in this sentence.
So, there has to be a way for you to:Code:{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard
There is a {\b bold} word in this sentence.\par
}
- Store the formatting data as well as the text, and
- interpret the formatting data in your application, so that you can draw the text properly.
Now, depending on what you mean by text, you can set the Font property on a label, or use a RichTextBox for a more advanced scenario.
But, for a more detail help, you'll have to provide additional info. What is it exactly that you're trying to do?
I have a .txt file.I have multilined text and I want to replace some of its words with some other word.So,whenever I replace a particular word,that word should be written in the text file as bold.
As mentioned above you can not work with different font info in a plain text file. You would need to use a different file type for your output as also mentioned above.
Which program are you using to view your text files?
Look at the documentation for that program and see what you need to insert into the text in order for it to display in bold.
See the examples given previously..
If you are viewing the file in one of the Coifs (Chrome, Opera, IE, Firefox, Safari browser) then you will need to insert..
There is a <b>bold</b> word in this sentence.
Usually, the extension of the file name, eg .HTM, .RTF, .DOCX determines the format of the text inside, so (unfortunately) there is not one fits all.
etc