简单的管理员解析? [英] simple admin parsing?

查看:117
本文介绍了简单的管理员解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿.我想知道是否有人知道在哪里可以找到一些简单的解析代码.我以前做过这样的事情,而且我知道还有其他事情.基本上,我将有一个文本框,管理员可以在其中设置电子邮件,我希望他们能够输入:
[名字]
[姓氏]
[TextToUseIfWeOnlyHaveEmail]先生或女士[/TextToUseIfWeOnlyHaveEmail]
我当然可以只在FirstName和LastName上执行文本替换,但是第三个替换文本会变得更加混乱,因此我尝试在网上查找内容.我真的想不出这叫什么,所以我很难找到它.星期一早上.

Hey. I was wondering if anyone knew where I could find some simple parsing code. I''ve done things like this before, and I know there are other things out there. Basically, I''m going to have a text box where admins can setup emails and i want them to be able to enter:
[FirstName]
[LastName]
[TextToUseIfWeOnlyHaveEmail]Sir Or Madam[/TextToUseIfWeOnlyHaveEmail]
I can certainly just do a text replace on FirstName and LastName, but the third one gets more confusing, so I tried to look for something online. I can''t really think of what this would be called, so my i''m having trouble finding it... bleh. Monday mornings.

推荐答案

如果您使用的是string.format,是否可以使用类似的内容:
If you''re using string.format could you use something like:
string email = "";
string str = string.Format("{0}\n{1}\n{2}...", "First name","Last name", string.IsNullOrEmpty(email) ? "": "Sir Or Madam");


并不真地.我最终只是这样做.仍然认为也许有一些代码可以使这份手册少一些.

not really. I ended up just doing this. Still think that maybe there''s some code out there to make this less manual.

RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline;
var unnamed = new Regex(@"\[TextIfUnnamed\](.*?)\[\/TextIfUnnamed\]", options);
var loginLink = new Regex(@"\[LoginLink\](.*?)\[\/LoginLink\]", options);

var temp = emailTemplateBody;
temp = temp.Replace("[LastName]", user.LastName);
temp = temp.Replace("[FirstName]", user.FirstName);

temp = unnamed.Replace(temp, x => x.Groups[1].Value);
temp = loginLink.Replace(temp, x => MakeLink(loginUrl, x.Groups[1].Value));

private string MakeLink(string url, string text){ return String.Format("<a href='{0}'>{1}</a'>", url, text); }


这篇关于简单的管理员解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆