Reputation: 360
Example:
Input: This is sample text
- this text is selected in textbox
Now I click button1 and:
Output: <b>This is sample text</b>
- this is not bold. I want just raw html tags without effects.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Xml.Linq;
using HtmlAgilityPack;
namespace program1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string url = "http://url.com/";
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument htmldoc = web.Load(url);
htmldoc.OptionFixNestedTags = true;
HtmlNode node = htmldoc.DocumentNode.SelectSingleNode("//h1[@class='class']");
string title = node.InnerText;
node = htmldoc.DocumentNode.SelectSingleNode("//div[@class='class2']");
string content = node.InnerText;
richTextBox1.Text = content;
textBox2.Text = title;
}
}
}
My language is not good then I drew what I mean.. but I need to 10 reputation to post images. Sorry.
Upvotes: 0
Views: 35
Reputation: 1139
This is it mostly working http://jsfiddle.net/tx3Gr/
HTML
<div id="mytext">Hello There</div><button>click me</button>
Javascript: (with jquery)
function safe_tags(str) {
return str.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') ;
}
$('button').on('click',
function(){
var txt = $('#mytext').text();
var txt1= safe_tags('<b>'+txt+'</b>');
$('#mytext').html(txt1)
});
Upvotes: 0
Reputation: 101701
In button1 Click you can do the following:
string newText = String.Format("<b>{0}</b>",textBox1.SelectedText);
textBox1.Text = textBox1.Replace(textBox1.SelectedText, newText);
I assume it is WinForms
Upvotes: 1