I am looking for the smartest way to convert a string with leading numbers into an integer value. It should use only the leading numbers in front of a text-string or 0 if there is no leading number. Currently I am using this code-snippet, but I hope there is a better way:
[int][regex]::Match('123test456','^d*').value
Or this. The automatic $matches hashtable variable has the answer if a match is found.
if ('123test456' -match '^d*') { $matches[0] } 123
1.4m articles
1.4m replys
5 comments
57.0k users