In Feburary 2016 08,
Start Windows PowerShell by clicking the Windows 'Start' button and typing 'powershell' into the 'Search programs and files' text box. This will open the Windows PowerShell console.
Type 'notepad split.ps1' in the PowerShell console to open Microsoft Notepad and create a new script called 'split.ps1.' Click 'Yes' when prompted by Notepad to allow the new file to be created.
Type the following commands into the new file, then save the file:$text = 'Windows PowerShell - Hello world!'$split = $text.split('-')echo $split[0]echo $split[1]First, a string is created named '$text' which holds the text to be split. The string is then split using the PowerShell 'Split' function, passing in the character the string is to be split by. In the code above, the string is split at the location of the hyphen. This creates an array in '$split' with two elements. The first element contains all the text up to the hyphen and the second element contains all the text after the hyphen. The contents of the two elements are then displayed to verify the command has worked.
Run the script in PowerShell by typing '.\split.ps1' and the display will show the output below, indicating the command was successful:Windows PowerShellHello World!
In Feburary 2016 08,
No comments:
Post a Comment