本文整理匯總了C#中System.Text.RegularExpressions.MatchCollection類的典型用法代碼示例。如果您正苦於以下問題:C# MatchCollection類的具體用法?C# MatchCollection怎麽用?C# MatchCollection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MatchCollection類屬於System.Text.RegularExpressions命名空間,在下文中一共展示了MatchCollection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: BuildAwardCache
/// <summary>
/// This method builds the award cache with the given data from the medal data file.
/// This method WILL CLEAR the award cache from any existing medals
/// </summary>
/// <param name="MedalsMatches"></param>
/// <param name="RanksMatches"></param>
public static void BuildAwardCache(MatchCollection MedalsMatches, MatchCollection RanksMatches)
{
// Clear out the award cache!
AwardCache.Clear();
// Convert each medal match into an object, and add it to the award cache
foreach (Match ArrayMatch in MedalsMatches)
{
AwardCache.AddAward(
new Award(
ArrayMatch.Groups["MedalIntId"].Value,
ArrayMatch.Groups["MedalStrId"].Value,
ArrayMatch.Groups["RewardType"].Value,
ParseCondition(ArrayMatch.Groups["Conditions"].Value)
)
);
}
// Convert ranks into objects, and also add them to the award cache
foreach (Match ArrayMatch in RanksMatches)
{
AwardCache.AddRank(
new Rank(
Int32.Parse(ArrayMatch.Groups["RankId"].Value),
ParseCondition(ArrayMatch.Groups["Conditions"].Value)
)
);
}
}
示例2: FindLongestConsecutivePair
private static string[] FindLongestConsecutivePair(MatchCollection usernames)
{
int bestLength = 0,
fromIndex = 0;
if (usernames.Count == 1)
{
Console.WriteLine(usernames[0].Value);
return new string[]
{
usernames[0].Value
};
}
for (int i = 1; i < usernames.Count; i++)
{
string current = usernames[i].Value,
prev = usernames[i - 1].Value;
int currentLength = current.Length + prev.Length;
if (currentLength > bestLength)
{
bestLength = currentLength;
fromIndex = i - 1;
}
}
return new string[]
{
usernames[fromIndex].Value,
usernames[fromIndex + 1].Value
};
}
示例3: RecursiveFindDynamicClause
public string RecursiveFindDynamicClause(MatchCollection matchs, SqlCommand sqlCommand)
{
string result = string.Empty;
if (matchs.Count < 1)
return result;
foreach (Match match in matchs)
{
result = match.Value;
string reResult = RecursiveFindDynamicClause(RegexPattern.DynamicClausePattern.Matches(match.Groups["DynamicClause"].Value), sqlCommand);
if (!sqlCommand.Parameters.Exists((c) =>
{
bool r = false;
string tempResult = string.IsNullOrEmpty(reResult) ? result : result.Replace(reResult, "");
if (SqlUtil.ContainsParameterName(tempResult, c.ParameterName))
{
//當值不為“null”、“DBNull”和“空白字符串”時參數值才算是有效
if (c.Value != null && c.Value != DBNull.Value && c.Value.ToString().Trim() != string.Empty)
{
r = true;
}
if (result.StartsWith(LEFT_BRACE_DUBLE_QUESTION_MARK))
{
r = true;
}
}
return r;
}))
{
removeClauseStack.Push(result);
}
}
return result;
}
示例4: BatchInsertIncidentCollections
public int BatchInsertIncidentCollections(MatchCollection collections, ConfigInitializer.IncidentTableEntity incidentTable, out HashSet<string> duplicateHash, bool SKIP)
{
duplicateHash = new HashSet<string>();
if (SKIP) return 0;
var queryText = incidentTable.ToString();
var incident = new DataNormalizer.DataEntity.Incident(incidentTable);
int successCount = 0;
//var queryText = $"INSERT into {this.tableInfo.tableName} {this.tableInfo.queryItemPattern} VALUES {this.tableInfo.queryValuePattern}";
using (var transaction = this._connection.BeginTransaction())
{
foreach (Match match in collections)
{
var cmd = new SqlCommand(queryText, this._connection, transaction);
incident.registerSqlCommand(match, ref cmd);
try
{
cmd.ExecuteNonQuery();
Console.WriteLine($"Insert: {match.Groups[1].Value}");
successCount += 1;
}
catch
{
var incidentString = match.Groups[1].Value;
duplicateHash.Add(incidentString);
Console.WriteLine($"Duplicate Incident: {incidentString}");
}
}
transaction.Commit();
}
return successCount;
}
示例5: Matched
public override void Matched(MatchCollection matches, uint posterID, uint victimID, DateTime now, MySqlConnection con, SingleNewscanRequestHandler handler, ParserResponse resp)
{
foreach (Match m in matches) {
MySqlCommand cleanup = new MySqlCommand(@"DELETE FROM techtree_useritems
USING (" + DBPrefix + @"techtree_useritems AS techtree_useritems) INNER JOIN (" + DBPrefix + @"techtree_items AS techtree_items) ON techtree_items.ID=techtree_useritems.itemid
WHERE techtree_useritems.uid=?uid AND techtree_items.type = 'for'", con);
cleanup.Parameters.Add("?uid", MySqlDbType.UInt32).Value = victimID;
cleanup.Prepare();
cleanup.ExecuteNonQuery();
String[] parts = m.Groups[1].Value.Split('\n');
MySqlCommand idQry = new MySqlCommand(@"SELECT ID FROM " + DBPrefix + @"techtree_items WHERE Name=?name", con);
idQry.Parameters.Add("?name", MySqlDbType.String);
idQry.Prepare();
MySqlCommand idInsert = new MySqlCommand(@"INSERT IGNORE INTO " + DBPrefix + @"techtree_useritems (uid, itemid, count) VALUES (?uid, ?itemid, 1)", con);
idInsert.Parameters.Add("?uid", MySqlDbType.UInt32).Value = victimID;
idInsert.Parameters.Add("?itemid", MySqlDbType.UInt32);
idInsert.Prepare();
foreach (String forschung in parts) {
idQry.Parameters["?name"].Value = forschung;
object res = idQry.ExecuteScalar();
if (res == null)
continue;
uint id = (uint)res;
idInsert.Parameters["?itemid"].Value = id;
idInsert.ExecuteNonQuery();
}
}
resp.Respond("Forschungsübersicht eingelesen!");
}
示例6: CreateCollection
private static IHtmlCollection CreateCollection(MatchCollection matches)
{
var elements = new List<IHtmlElement>();
foreach (Match match in matches)
elements.Add(CreateElement(match));
return new HtmlCollection(elements);
}
示例7: getLinkList
private List<Link> getLinkList(MatchCollection matches)
{
List<Link> links = new List<Link>();
for (int i = 0; i < matches.Count; i++)
addLink(i, matches, links);
return links;
}
示例8: Matched
public override void Matched(MatchCollection matches, uint posterID, uint victimID, DateTime now, MySqlConnection con, SingleNewscanRequestHandler handler, ParserResponse resp)
{
Dictionary<uint, String> uidToIgmNameCache = new Dictionary<uint, string>();
foreach(Match outerMatch in matches) {
String empfaenger;
if(!uidToIgmNameCache.TryGetValue(victimID, out empfaenger)) {
MySqlCommand igmNameQry = new MySqlCommand("SELECT igmname FROM " + DBPrefix + "igm_data WHERE id=?igmid", con);
igmNameQry.Parameters.Add("?igmid", MySqlDbType.UInt32).Value = victimID;
Object obj = igmNameQry.ExecuteScalar();
empfaenger = (String)obj;
uidToIgmNameCache.Add(victimID, empfaenger);
}
Transport t = new Transport(
uint.Parse(outerMatch.Groups[1].Value),
uint.Parse(outerMatch.Groups[2].Value),
uint.Parse(outerMatch.Groups[3].Value),
empfaenger,
outerMatch.Groups[5].Value,
IWDBUtils.parsePreciseIWTime(outerMatch.Groups[4].Value)
);
MatchCollection c = Regex.Matches(outerMatch.Groups[7].Value, @"\s(" + RessourcenName + @")\s+(" + Number + ")");
foreach(Match m in c) {
t.SetRess(m.Groups[1].Value, int.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.Any));
}
t.ToDB(con, DBPrefix, handler.BesData, resp, "Übergabebericht");
}
}
示例9: getVulnerablePages
private void getVulnerablePages(MatchCollection mirrors) {
foreach (var pageUrl in mirrors) {
string data = tryGetUrlData(BASE_URL + pageUrl);
extractUrl(data);
extractAndSaveHtmlPage(data);
}
}
示例10: ParseMeters
private void ParseMeters(MatchCollection matches)
{
string metersString = matches[1].Groups[0].Value.Trim();
string[] arrayMeters = metersString.Split(new char[] { ' ' });
string meterValue = arrayMeters[0];
meters = double.Parse(meterValue);
}
示例11: cleanLinks
private static Collection<LinkItem> cleanLinks(MatchCollection m1)
{
Collection<LinkItem> list = new Collection<LinkItem>();
// 2.
// Loop over each match.
foreach (Match m in m1)
{
string value = m.Groups[1].Value;
// 3.
// Get href attribute.
Match m2 = Regex.Match(value, @"href=\""(.*?)\""",
RegexOptions.Singleline);
if (m2.Success)
{
LinkItem i = new LinkItem();
i.Href = m2.Groups[1].Value;
// 4.
// Remove inner tags from text and add.
string t = Regex.Replace(value, @"\s*<.*?>\s*", "",
RegexOptions.Singleline);
i.Text = t;
list.Add(i);
}
}
return list;
}
示例12: cleanLinks2
private static Collection<LinkItem> cleanLinks2(MatchCollection m1)
{
Collection<LinkItem> list = new Collection<LinkItem>();
// 2.
// Loop over each match.
foreach (Match m in m1)
{
string value = m.Groups[1].Value;
LinkItem i = new LinkItem();
int pos = value.IndexOf(' ');
if (pos == -1)
{
pos = value.IndexOf('\n');
}
if (pos == -1)
{
pos = value.IndexOf('\t');
}
if (pos != -1)
{
value = value.Substring(0, pos);
}
pos = value.IndexOf('<');
if (pos != -1)
{
value = value.Substring(0, pos);
}
i.Href = value;
list.Add(i);
}
return list;
}
示例13: Extract
/// <summary>
/// Extracts the matches of this pattern from <paramref name="source" />.
/// </summary>
/// <param name="fileName">The name of the file associated with <paramref name="source" />.</param>
/// <param name="source">The source string</param>
/// <returns>
/// A collection of found matches.
/// </returns>
public MatchCollection Extract(string fileName, string source)
{
MatchCollection resultMatches = new MatchCollection();
LineCounter lineCounter = new LineCounter(source);
RegexMatch regexMatch = scanner.Match(source);
while (regexMatch.Success)
{
Match match = new Match();
match["Path"] = Path.GetDirectoryName(fileName);
match["File"] = Path.GetFileName(fileName);
match["LineNumber"] = lineCounter.CountTo(regexMatch.Index).InvariantToString();
foreach (string groupName in scanner.GetGroupNames())
{
// ignore default-names like '0', '1' ... as produced
// by the Regex class
if (Char.IsLetter(groupName[0]) || (groupName[0] == '_'))
{
match[groupName] = ConcatenateCaptures(regexMatch.Groups[groupName]);
}
}
resultMatches.Add(match);
regexMatch = regexMatch.NextMatch();
}
return resultMatches;
}
示例14: AutoGenerateChildren
public void AutoGenerateChildren(MatchCollection matches)
{
int count = 0;
m_App.CacheStore.StartUpdate();
foreach (Match match in matches)
{
DegreeMinutes[] coord = Utilities.ParseCoordString (match.Captures[0].Value);
System.Console.WriteLine (Utilities.getCoordString (coord[0], coord[1]));
Waypoint newPoint = new Waypoint ();
Geocache parent = m_Cache;
newPoint.Symbol = "Reference Point";
newPoint.Parent = parent.Name;
newPoint.Lat = coord[0].GetDecimalDegrees ();
newPoint.Lon = coord[1].GetDecimalDegrees ();
newPoint.Desc = Catalog.GetString ("Grabbed Waypoint");
String name = "RP" + parent.Name.Substring (2);
if (m_App.AppConfig.IgnoreWaypointPrefixes)
{
name = parent.Name;
}
name = m_App.CacheStore.GetUniqueName(name);
newPoint.Name = name;
m_App.CacheStore.AddWaypointOrCache(newPoint, false, false);
count++;
}
m_App.CacheStore.CompleteUpdate();
m_App.RefreshAll();
}
示例15: RegExpMatch
internal RegExpMatch(ArrayPrototype parent, Regex regex, Match match, string input) : base(parent, typeof(RegExpMatch))
{
this.hydrated = false;
this.regex = regex;
this.matches = null;
this.match = match;
base.SetMemberValue("input", input);
base.SetMemberValue("index", match.Index);
base.SetMemberValue("lastIndex", (match.Length == 0) ? (match.Index + 1) : (match.Index + match.Length));
string[] groupNames = regex.GetGroupNames();
int num = 0;
for (int i = 1; i < groupNames.Length; i++)
{
string name = groupNames[i];
int num3 = regex.GroupNumberFromName(name);
if (name.Equals(num3.ToString(CultureInfo.InvariantCulture)))
{
if (num3 > num)
{
num = num3;
}
}
else
{
Group group = match.Groups[name];
base.SetMemberValue(name, group.Success ? group.ToString() : null);
}
}
this.length = num + 1;
}