473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

BBCodes for .net?

Hello, I want to allow my users to type in some codes, like the BBCodes. The
codes i had in mind were:

[bold]Message[/bold]
[italic]Message[/italic]
[strikethru]Message[/strikethru]
Message
Message
Message

[zitat=username]Message[/zitat] <-- here i need the username to be
transferd into a variable so i can fetch the corresponding post and then
replaced by the post returned form the DB
[internallink=private/adress.aspx?ID=5]Rules[/internallink] <-- program
should automatically add <a href ... /zone/ and then the url and then the
message </a>
[threadlink=687]Message[/threadlink] <-- program should automatically add
<a href ... zone/board/answer.aspx?TopicID= and then the number supplied and
then the message </a>
Message
[em********@pafo.net]Message[/email]

Whats the best way to achive this?
Also, i want to make sure that the end tag is after the opening tag,
otherwise it could be pretty bad, like:

Message <-- No end link

or

[link=www.goole.com]Message <-- End link before link

these would case the rest of my site to become a link. (using c#)

Patrick
Feb 11 '07 #1
2 1171
Howdy Patrick,

Use regular expressions. Please find a simple example i prepared to show you
the concept

-- begin c# code --

public static string ReplaceZizats(string input)
{
// one from many possible patterns,
// @"\[zitat=(\w+)](.+)\[/zitat]"
string pattern = @"\[zitat=([^\]]*)\]([^\[]*)\[/zitat\]";

return System.Text.RegularExpressions.Regex.Replace(input , pattern,
new MatchEvaluator(ZizatMatchEvaluator));
}

private static string ZizatMatchEvaluator(
System.Text.RegularExpressions.Match match)
{
if (match.Success)
{
string username = match.Groups[1];
string message = match.Groups[2];

// get the post from database using above variables
// ...

return String.Format("<a href=\"postspage.aspx?postId={0}\">{1}</a>",
postId, message);
}
else
{
return match.Value;
}
}
-- end c# code --

Milosz

"Patrick F" wrote:
Hello, I want to allow my users to type in some codes, like the BBCodes. The
codes i had in mind were:

[bold]Message[/bold]
[italic]Message[/italic]
[strikethru]Message[/strikethru]
Message
Message
Message

[zitat=username]Message[/zitat] <-- here i need the username to be
transferd into a variable so i can fetch the corresponding post and then
replaced by the post returned form the DB
[internallink=private/adress.aspx?ID=5]Rules[/internallink] <-- program
should automatically add <a href ... /zone/ and then the url and then the
message </a>
[threadlink=687]Message[/threadlink] <-- program should automatically add
<a href ... zone/board/answer.aspx?TopicID= and then the number supplied and
then the message </a>
Message
[em********@pafo.net]Message[/email]

Whats the best way to achive this?
Also, i want to make sure that the end tag is after the opening tag,
otherwise it could be pretty bad, like:

Message <-- No end link

or

[link=www.goole.com]Message <-- End link before link

these would case the rest of my site to become a link. (using c#)

Patrick

Feb 12 '07 #2
Tiny bug:
string username = match.Groups[1];
string message = match.Groups[2];
Should be:

string username = match.Groups[1].Value;
string message = match.Groups[2].Value;

--
Milosz
"Milosz Skalecki [MCAD]" wrote:
Howdy Patrick,

Use regular expressions. Please find a simple example i prepared to show you
the concept

-- begin c# code --

public static string ReplaceZizats(string input)
{
// one from many possible patterns,
// @"\[zitat=(\w+)](.+)\[/zitat]"
string pattern = @"\[zitat=([^\]]*)\]([^\[]*)\[/zitat\]";

return System.Text.RegularExpressions.Regex.Replace(input , pattern,
new MatchEvaluator(ZizatMatchEvaluator));
}

private static string ZizatMatchEvaluator(
System.Text.RegularExpressions.Match match)
{
if (match.Success)
{
string username = match.Groups[1];
string message = match.Groups[2];

// get the post from database using above variables
// ...

return String.Format("<a href=\"postspage.aspx?postId={0}\">{1}</a>",
postId, message);
}
else
{
return match.Value;
}
}
-- end c# code --

Milosz

"Patrick F" wrote:
Hello, I want to allow my users to type in some codes, like the BBCodes. The
codes i had in mind were:

[bold]Message[/bold]
[italic]Message[/italic]
[strikethru]Message[/strikethru]
Message
Message
Message

[zitat=username]Message[/zitat] <-- here i need the username to be
transferd into a variable so i can fetch the corresponding post and then
replaced by the post returned form the DB
[internallink=private/adress.aspx?ID=5]Rules[/internallink] <-- program
should automatically add <a href ... /zone/ and then the url and then the
message </a>
[threadlink=687]Message[/threadlink] <-- program should automatically add
<a href ... zone/board/answer.aspx?TopicID= and then the number supplied and
then the message </a>
Message
[em********@pafo.net]Message[/email]

Whats the best way to achive this?
Also, i want to make sure that the end tag is after the opening tag,
otherwise it could be pretty bad, like:

Message <-- No end link

or

[link=www.goole.com]Message <-- End link before link

these would case the rest of my site to become a link. (using c#)

Patrick
Feb 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: phil hunt | last post by:
Does anyone know of a text-to-HTML processing program, ideally written in Python because I'll probably be wanting to make small modifications to it, which is simple and straightforward to use and...
11
by: frizzle | last post by:
Hi groupies I'm building a news site, to wich a user can add new items into a mySQL db. It's still in testfase, but it's so extremely slow, i want to figure out what i'm doing wrong, or what to...
3
by: jonathan.beckett | last post by:
Hi all, I released a new version of the "PluggedOut Blog" script at the weekend - it's a PHP/MySQL solution for blogs, journals, diaries or any kind of calendar application. Homepage......
0
by: jonathan.beckett | last post by:
Version 1.9.9f of the PluggedOut Blog script is now available for download. PluggeOut Blog is a free, open source blog/diary/journal script, written by a professional software developer to give...
0
by: jonathan.beckett | last post by:
Version 1.9.9h of the PluggedOut Blog script is now available for download. The latest version fixes numerous issues with earlier versions, and introduces lots improvements asked for by users. ...
4
by: Gary | last post by:
Hi, I get this error " " when my web page run, what does it mean? Hope someone can help!!! Gary
8
by: jeddiki | last post by:
Many forums and also Joomla make use of BBcodes to allow us to Bold and italic in the posts. How can I find out if I have this capability on my server ? Is there something in the php.ini that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.