A practical example showing the difference between counting all matches and counting matches for a specific rule.
ID: 786
See: Count
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("Header
Paragraph 1.
Paragraph 2.
");
// Define rules for different tags
var h1Rule = t.Pattern("{text}
");
var pRule = t.Pattern("{text}
");
t.Find();
// Get the total count of all matches from all rules
Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}");
// Get the count for only the paragraph rule
Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}");
Total matches (all rules): 3
Paragraph matches only: 2 using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Str("<h1>Header</h1><p>Paragraph 1.</p><p>Paragraph 2.</p>"); // Define rules for different tags var h1Rule = t.Pattern("<h1>{text}</h1>"); var pRule = t.Pattern("<p>{text}</p>"); t.Find(); // Get the total count of all matches from all rules Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}"); // Get the count for only the paragraph rule Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Str("Header
Paragraph 1.
Paragraph 2.
");
// Define rules for different tags
auto h1Rule = t.Pattern("{text}
");
auto pRule = t.Pattern("{text}
");
t.Find();
// Get the total count of all matches from all rules
cout << "Total matches (all rules): " << t.Matches().Count() << endl;
// Get the count for only the paragraph rule
cout << "Paragraph matches only: " << pRule.Matches().Count() << endl;
}
Total matches (all rules): 3
Paragraph matches only: 2 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Str("<h1>Header</h1><p>Paragraph 1.</p><p>Paragraph 2.</p>"); // Define rules for different tags auto h1Rule = t.Pattern("<h1>{text}</h1>"); auto pRule = t.Pattern("<p>{text}</p>"); t.Find(); // Get the total count of all matches from all rules cout << "Total matches (all rules): " << t.Matches().Count() << endl; // Get the count for only the paragraph rule cout << "Paragraph matches only: " << pRule.Matches().Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Str("Header
Paragraph 1.
Paragraph 2.
")
'// Define rules for different tags
Dim h1Rule = t.Pattern("{text}
")
Dim pRule = t.Pattern("{text}
")
t.Find()
'// Get the total count of all matches from all rules
Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}")
'// Get the count for only the paragraph rule
Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}")
End Sub
End Module
Total matches (all rules): 3
Paragraph matches only: 2 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Str("<h1>Header</h1><p>Paragraph 1.</p><p>Paragraph 2.</p>") '// Define rules for different tags Dim h1Rule = t.Pattern("<h1>{text}</h1>") Dim pRule = t.Pattern("<p>{text}</p>") t.Find() '// Get the total count of all matches from all rules Console.WriteLine($"Total matches (all rules): {t.Matches.Count()}") '// Get the count for only the paragraph rule Console.WriteLine($"Paragraph matches only: {pRule.Matches.Count()}") End Sub End Module