Forum > ASP.NET 1.x och 2.x > Språk - C#
hejsan, jag undrar hur jag ersätter <?php med en annan sträng?
Jag har den här koden:
string BBCode(string strTextToReplace)
{
Regex regExp;
regExp = new Regex("\\[url\\]([^\\]]+)\\[\\/url\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<a href=\"$1\">$1</a>");
regExp = new Regex("\\[url=([^\\]]+)\\]([^\\]]+)\\[\\/url\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<a href=\"$1\">$2</a>");
regExp = new Regex("\\[img\\]([^\\]]+)\\[\\/img\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<img src=\"$1\" />");
regExp = new Regex("\\[b\\](.+?)\\[\\/b\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<b>$1</b>");
regExp = new Regex("\\[i\\](.+?)\\[\\/i\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<i>$1</i>");
regExp = new Regex("\\[u\\](.+?)\\[\\/u\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<u>$1</u>");
regExp = new Regex("\\[size=([^\\]]+)\\]([^\\]]+)\\[\\/size\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<span style=\"font-size: $1px\">$2</span>");
regExp = new Regex("\\[color=([^\\]]+)\\]([^\\]]+)\\[\\/color\\]");
strTextToReplace = regExp.Replace(strTextToReplace, "<span style=\"color: $1\">$2</span>");
return strTextToReplace;
}
Redigerad av Petters_Web
Anledning:
| Skriv utProva:
strTextToReplace = strTextToReplace.Replace("<?", "<?");
strTextToReplace = strTextToReplace.Replace("?>", "?>");