本文整理匯總了C#中System.Text.RegularExpressions.Regex.IndexOf方法的典型用法代碼示例。如果您正苦於以下問題:C# Regex.IndexOf方法的具體用法?C# Regex.IndexOf怎麽用?C# Regex.IndexOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.IndexOf方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ParseAdditionalInformation
protected override void ParseAdditionalInformation()
{
string bankName = new Regex(@"/BBK/.*\|?").Match(statementLine).Value;
if (!string.IsNullOrEmpty(bankName))
{
bankName = bankName.Substring(5);
if (bankName.EndsWith("|"))
{
bankName = bankName.Substring(0, bankName.Length - 1);
}
int vertical = bankName.IndexOf("|");
if (-1 < vertical)
{
bankName = bankName.Substring(0, vertical);
}
bankStatement.CptyBankName = bankName.Trim();
}
AddInformation();
//put tag 86 information to remark
string[] remarks = statementLine.Split(new string[] { TAG_ADDITIONAL_INFO }, StringSplitOptions.None);
if (remarks.Length > 1)
{
bankStatement.Remark = remarks[1];
}
}
示例2: BeautyMyCode
private string BeautyMyCode(string Source)
{
Source = RemoveStr(Source, new string[] { "\n", "\x09", " " });
Source = new Regex("#include <(.*?)>").Replace(Source, "$0\n");
Source = new Regex(";").Replace(Source, "$0\n");
Source = new Regex("{").Replace(Source, "\n$0\n");
Source = new Regex("}").Replace(Source, "$0\n");
int DeepCount = 0;
for (int i = 0; i < Source.Length; i++)
{
if (Source[i] == '}') DeepCount--;
else if (Source[i] == '{') DeepCount++;
else if (Source[i] == '\n')
{
int NextNewLinePos = Source.IndexOf("\n", i + 1);
if (NextNewLinePos != -1)
{
Console.WriteLine(Source.Substring(i, NextNewLinePos - i));
if (Source.Substring(i, NextNewLinePos - i).Contains("}"))
{
Source = Source.Insert(i + 1, GetManyBlankStr(DeepCount -1));
}
else
{
Source = Source.Insert(i + 1, GetManyBlankStr(DeepCount));
}
}
}
}
return (Source);
}
示例3: RepairLog
public void RepairLog()
{
CheckLogsDirectoryPath();
CheckDateStamp();
string logPath = LogsDirectoryPath + Path.DirectorySeparatorChar + LogDateStamp + Path.DirectorySeparatorChar + LogFileName;
string fixedLogPath = LogsDirectoryPath + Path.DirectorySeparatorChar + LogDateStamp + Path.DirectorySeparatorChar + RepairedLogFileName;
string logContents;
using (StreamReader reader = new StreamReader(logPath))
{
logContents = reader.ReadToEnd();
reader.Close();
}
// Remove any duplicate <Log>...</Log> tags
logContents = new Regex("</Log>(.|\r\n)*?<Log>", RegexOptions.IgnoreCase | RegexOptions.Multiline)
.Replace(logContents, "");
// Add the start <Log> tag if necessary
string startTag = "<Log>";
if (logContents.IndexOf(startTag) == -1)
logContents = startTag + "\r\n" + logContents;
// Add the XML declaration if necessary
// This must be done before after the start tag prepend won't work
string xmlDeclaration = "<?xml version=\'1.0\'?>";
if (logContents.IndexOf(xmlDeclaration) == -1)
logContents = xmlDeclaration + "\r\n" + logContents;
// Add the ending </Log> tag if necessary
if (logContents.IndexOf("</Log>") == -1)
logContents = logContents + "</Log>";
using (StreamWriter writer = File.CreateText(fixedLogPath))
{
writer.Write(logContents);
writer.Close();
}
}
示例4: EquationsFromParentheses
public static IEnumerable<string> EquationsFromParentheses(string recipe)
{
var equations = new List<string>();
if (string.IsNullOrWhiteSpace(recipe))
{
return equations;
}
recipe = "(" + recipe + ")"; // If this is a duplication of effort, we'll silently ignore it later.
recipe = new Regex(@"\s+").Replace(recipe, string.Empty); // Remove all whitespace.
recipe = LeveledPreparser(recipe);
var multiLetterMatch = invalidLetterFinder.Match(recipe);
if (multiLetterMatch.Success)
{
throw new ArgumentException("The gem \"" + multiLetterMatch.Value + "\" must be a single letter. Gem combinations must be expressed as individual components separated with plus signs and brackets, as needed. For example:\nob → o+b\nob+o → (o+b)+o");
}
var id = 0;
foreach (var c in Gem.GemInitializer)
{
if (recipe.IndexOf(c) > -1)
{
recipe = recipe.Replace(c, id.ToString(CultureInfo.InvariantCulture)[0]);
equations.Add(string.Format(CultureInfo.InvariantCulture, "{0}={1}", id, c));
id++;
}
}
if (equations.Count == 0)
{
throw new ArgumentException("Recipe did not contain any recognizable gems.");
}
// Scan for plus signs within the formula and add gems together appropriately.
int plus = recipe.IndexOf('+');
string newNum = (id - 1).ToString(CultureInfo.InvariantCulture);
while (plus > -1)
{
string thisCombine;
var close = recipe.IndexOf(')', plus);
if (close >= 0)
{
var open = recipe.LastIndexOf('(', close);
if (open < 0)
{
throw new ArgumentException("Bracket mismatch in formula.");
}
thisCombine = recipe.Substring(open + 1, close - open - 1);
string[] combineGems = thisCombine.Split('+');
if (combineGems.Length != 2)
{
throw new ArgumentException("The formula provided contains more than a single plus sign within a pair of brackets or a term that is over-bracketed (e.g., \"((o+o))\"). These are not currently supported.");
}
if (combineGems[0].Length == 0 || combineGems[1].Length == 0)
{
throw new ArgumentException("Invalid formula part: (" + thisCombine + ")");
}
newNum = id.ToString(CultureInfo.InvariantCulture);
recipe = recipe.Replace("(" + thisCombine + ")", newNum);
equations.Add(string.Format(CultureInfo.InvariantCulture, "{0}={1}+{2}", id, combineGems[0], combineGems[1]));
}
else
{
throw new ArgumentException("Bracket mismatch in formula.");
}
plus = recipe.IndexOf('+');
id++;
}
while (recipe.StartsWith("(", StringComparison.Ordinal) && recipe.EndsWith(")", StringComparison.Ordinal))
{
recipe = recipe.Substring(1, recipe.Length - 2);
}
if (recipe != newNum)
{
if (recipe.Contains("("))
{
throw new ArgumentException("Bracket mismatch in formula.");
}
throw new ArgumentException("Invalid recipe.");
}
return equations;
}
示例5: OnInit
//.........這裏部分代碼省略.........
}
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++) {
file = sbFile2[i].Trim().TrimStart('.');
if (file.Equals("")) continue;
try { size = LongExtensions.FormatKB((new System.IO.FileInfo(file)).Length); } catch { size = "0"; }
sbFile3.Append(file.Replace(localPath, "").Replace("\\", "/") + " (" + size + ")" + Environment.NewLine);
if (i.Equals(sbFile2.Count - 2)) sbFile3.Append("(" + sbFile2.Count + ")" + Environment.NewLine);
}
} catch {
Msg.WriteEnd(string.Format(strList[1], file, "read path"));
}
text = localPath + "<br /><textarea id=\"txtText\" cols=\"100\" rows=\"20\">" + sbFile3.ToString() + "</textarea>";
Msg.WriteEnd(string.Format(strList[0], text, "read path"));
break;
case "db:":
file = file.Replace("/r/n", Environment.NewLine).Trim('/');
if (file.IndexOf(Environment.NewLine + "GO" + Environment.NewLine) != -1) {
Data.ExecuteCommandWithSplitter(file, "GO");
Msg.WriteEnd(string.Format(strList[0], "", "read db"));
} else {
text = file + "<br /><textarea id=\"txtText\" cols=\"100\" rows=\"20\">" + Data.GetDataSet(file).ToJson() + "</textarea>";
Msg.WriteEnd(string.Format(strList[0], text, "read db"));
}
break;
default: Msg.WriteEnd("file error!"); break;
}
Response.End();
break;
case "ok": localPath = "~/tmp/".GetMapPath();
System.Collections.Generic.IList<string> fileList = new System.Collections.Generic.List<string>();
FileDirectory.FileList(localPath, ref fileList, localPath);
for (int i = 0; i < fileList.Count; i++) {
file = fileList[i].Trim().TrimStart('.');
if (file.Length < 2) continue;
fileName = localPath + file;
isTrue = FileDirectory.FileCopy(fileName, Server2.GetMapPath("~/") + file, true);
if (isTrue) FileDirectory.FileDelete(fileName);
if (isTrue) Response.Write(string.Format(strList[0], file, "update") + "<br />"); else Response.Write(string.Format(strList[1], file, "update") + "<br />");
}
Response.End();
break;
case "ef":
localPath = Request2.GetF("file").Trim();
string content = Request2.GetF("data").Trim();
FileDirectory.FileDelete(localPath);
isTrue = FileDirectory.FileWrite(localPath, content, Encoding.UTF8);
if (isTrue) Msg.WriteEnd("edit file ok!"); else Msg.WriteEnd("edit file error!");
break;
}
}