Checks for the existence of a required header in a string.
ID: 1341
using uCalcSoftware;
var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
var text_ok = "Header: OK";
var text_fail = "Header: ERROR";
// This rule only matches if the status is "OK"
t.Pattern("Header: OK");
// Find() returns the transformer, so we can chain Matches().Count()
if (t.SetText(text_ok).Find().Matches.Count() > 0) {
Console.WriteLine("text_ok is valid.");
}
if (t.SetText(text_fail).Find().Matches.Count() == 0) {
Console.WriteLine("text_fail is invalid.");
}
}
text_ok is valid.
text_fail is invalid. using uCalcSoftware; var uc = new uCalc(); using (var t = new uCalc.Transformer()) { var text_ok = "Header: OK"; var text_fail = "Header: ERROR"; // This rule only matches if the status is "OK" t.Pattern("Header: OK"); // Find() returns the transformer, so we can chain Matches().Count() if (t.SetText(text_ok).Find().Matches.Count() > 0) { Console.WriteLine("text_ok is valid."); } if (t.SetText(text_fail).Find().Matches.Count() == 0) { Console.WriteLine("text_fail is invalid."); } }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::Transformer t;
t.Owned(); // Causes t to be released when it goes out of scope
auto text_ok = "Header: OK";
auto text_fail = "Header: ERROR";
// This rule only matches if the status is "OK"
t.Pattern("Header: OK");
// Find() returns the transformer, so we can chain Matches().Count()
if (t.SetText(text_ok).Find().Matches().Count() > 0) {
cout << "text_ok is valid." << endl;
}
if (t.SetText(text_fail).Find().Matches().Count() == 0) {
cout << "text_fail is invalid." << endl;
}
}
}
text_ok is valid.
text_fail is invalid. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::Transformer t; t.Owned(); // Causes t to be released when it goes out of scope auto text_ok = "Header: OK"; auto text_fail = "Header: ERROR"; // This rule only matches if the status is "OK" t.Pattern("Header: OK"); // Find() returns the transformer, so we can chain Matches().Count() if (t.SetText(text_ok).Find().Matches().Count() > 0) { cout << "text_ok is valid." << endl; } if (t.SetText(text_fail).Find().Matches().Count() == 0) { cout << "text_fail is invalid." << endl; } } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using t As New uCalc.Transformer()
Dim text_ok = "Header: OK"
Dim text_fail = "Header: ERROR"
'// This rule only matches if the status is "OK"
t.Pattern("Header: OK")
'// Find() returns the transformer, so we can chain Matches().Count()
If t.SetText(text_ok).Find().Matches.Count() > 0 Then
Console.WriteLine("text_ok is valid.")
End If
If t.SetText(text_fail).Find().Matches.Count() = 0 Then
Console.WriteLine("text_fail is invalid.")
End If
End Using
End Sub
End Module
text_ok is valid.
text_fail is invalid. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using t As New uCalc.Transformer() Dim text_ok = "Header: OK" Dim text_fail = "Header: ERROR" '// This rule only matches if the status is "OK" t.Pattern("Header: OK") '// Find() returns the transformer, so we can chain Matches().Count() If t.SetText(text_ok).Find().Matches.Count() > 0 Then Console.WriteLine("text_ok is valid.") End If If t.SetText(text_fail).Find().Matches.Count() = 0 Then Console.WriteLine("text_fail is invalid.") End If End Using End Sub End Module