≡ Menu

PowerShell: Converting String into a char array

I have seen hits from people coming to my blog with query string “converting string to a char array”. I don’t a post which shows how to do this but a similar post(http://techibee.com/powershell/know-about-ofs-a-special-variable-in-powershell/794) in my blog is catching these hits. Since many peopel are looking for this, I felt I should write one.

Converting a string into a character array is very straight forward. For example, take a string $website=”techibee.com”. Here $website is a string and if you want to convert this into a array of characters each letter fitting into one item in array, then just use [char[]]$website and you are done. You can go through the below little script for demonstration.

[string]$website = “TechiBee.com”

$chararray = [char[]]$website

write-host $chararray

#You can pick the element you want by passing the number to array index

write-host $chararray[2]

#You can also see what type of object $chararray is by invoking below command


Hope this little script helps you..


{ 1 comment… add one }

Leave a Comment