tag:blogger.com,1999:blog-3087006298434777887.post8899126709808381741..comments2024-02-20T10:37:47.708-08:00Comments on Dinusha's Blog: PowerShell : count occurrences of specific character in a stringDinusha Kumarasirihttp://www.blogger.com/profile/08644048913577767545noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-3087006298434777887.post-27940798737575295212022-07-17T12:07:24.380-07:002022-07-17T12:07:24.380-07:00Just as a tip, you might have to cast the object t...Just as a tip, you might have to cast the object to a string or convert it to a string using .ToString before doing .ToCharArrayUnknownhttps://www.blogger.com/profile/18409954962802620490noreply@blogger.comtag:blogger.com,1999:blog-3087006298434777887.post-47029211471467337112021-12-01T05:25:54.327-08:002021-12-01T05:25:54.327-08:00($url.Split('/')).count-1
Is not correct,...<b>($url.Split('/')).count-1</b><br /><br />Is not correct, as it counts the split elements and not the number of appearances of the character we are looking for. Might be nit-picking, but still. Code right.<br /><br /><br /><b>($url.ToCharArray() -eq '"').count</b><br /><br />This is but correct, we get the number of the characters we are looking for.Anonymoushttps://www.blogger.com/profile/17159128400411100715noreply@blogger.comtag:blogger.com,1999:blog-3087006298434777887.post-62623960128248226342020-09-12T11:09:59.940-07:002020-09-12T11:09:59.940-07:00Here is a nice one if you want to count each of th...Here is a nice one if you want to count each of the char in a string.<br /><br />$url = "http://sp13/sites/1/2/3")<br />$url.ToCharArray() | group<br /><br />Count Name Group<br />----- ---- -----<br /> 1 h {h}<br /> 3 t {t, t, t}<br /> 2 p {p, p}<br /> 1 : {:}<br /> 6 / {/, /, /, /...}<br /> 3 s {s, s, s}<br /> 2 1 {1, 1}<br /> 2 3 {3, 3}<br /> 1 i {i}<br /> 1 e {e}<br /> 1 2 {2}Unknownhttps://www.blogger.com/profile/07005511617445587284noreply@blogger.comtag:blogger.com,1999:blog-3087006298434777887.post-50360915292749223962020-07-11T06:40:51.591-07:002020-07-11T06:40:51.591-07:00Thanks for posting this info. I just want to let y...Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. <a href="http://www.experts123.com/q/how-long-is-16000-characters.html" rel="nofollow">this</a><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3087006298434777887.post-72034625778347072002020-04-03T07:18:44.806-07:002020-04-03T07:18:44.806-07:00($url.ToCharArray() -eq '"').count
E...($url.ToCharArray() -eq '"').count<br /><br />Even clearer! :DNostraDavidhttps://www.blogger.com/profile/12252064224448709801noreply@blogger.comtag:blogger.com,1999:blog-3087006298434777887.post-33428567559750758282018-08-22T10:10:26.335-07:002018-08-22T10:10:26.335-07:00Much better and faster way
($url.Split('/'...Much better and faster way<br /><br />($url.Split('/')).count-1Unknownhttps://www.blogger.com/profile/07005511617445587284noreply@blogger.comtag:blogger.com,1999:blog-3087006298434777887.post-64513003593485252742018-01-31T09:51:25.302-08:002018-01-31T09:51:25.302-08:00Another way:
$newString = $oldString -replace &quo...Another way:<br />$newString = $oldString -replace "x", ""<br />$count = $oldString.Length - $newString.Length<br />aodennisonhttps://www.blogger.com/profile/17591897936734824813noreply@blogger.comtag:blogger.com,1999:blog-3087006298434777887.post-3789686759277174952016-08-10T08:23:14.269-07:002016-08-10T08:23:14.269-07:00Thanks!Thanks!Anonymoushttps://www.blogger.com/profile/10513854955573235751noreply@blogger.com