by andy81 · 3y ago · 0 comments
It's for parsing rather than search though, you'd still need regex if e.g. searching unstructured logs for IPs.
e.g. (powershell syntax for easy reproduction) returns parsed, or throw if invalid. [uri]"\\ServerName1\Folder\UserName" [version]'1.2.3.4' [ipaddress]'1.1.1.1'
if (int.TryParse(userInput, out var number))
{
total += number;
}
This is cleaner code compared to try/catch and usually faster (though debatable if it matters) [2].[1] https://learn.microsoft.com/en-us/dotnet/api/system.net.ipad...