0
0
PowerShellscripting~30 mins

String methods (.Split, .Replace, .Trim) in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Using String Methods: .Split, .Replace, .Trim in PowerShell
📖 Scenario: You work in a small office where you receive a list of employee names and their departments in a single string. The data is messy with extra spaces and inconsistent separators. You want to clean and organize this data for a report.
🎯 Goal: Learn how to use PowerShell string methods .Split(), .Replace(), and .Trim() to clean and organize text data.
📋 What You'll Learn
Create a string variable with employee data separated by semicolons
Create a variable to hold the separator character
Use .Split() with the separator variable to split the string into an array
Use .Replace() to fix a typo in the data
Use .Trim() to remove extra spaces from each employee entry
Print the cleaned list of employees
💡 Why This Matters
🌍 Real World
Cleaning and organizing text data is common when working with user input, logs, or reports. String methods help automate these tasks.
💼 Career
PowerShell scripting with string manipulation is useful for system administrators and automation engineers to prepare data for reports or further processing.
Progress0 / 5 steps
1
Create the employee data string
Create a string variable called employeeData with this exact value: "John Doe ; Jane Smith ; Bob Johnson ; Alice Brown"
PowerShell
Need a hint?

Use double quotes to create the string and assign it to employeeData.

2
Create the separator variable
Create a variable called separator and set it to the semicolon character ";"
PowerShell
Need a hint?

Use double quotes around the semicolon character.

3
Split the string into an array
Use the .Split() method on employeeData with separator to create an array called employeeList
PowerShell
Need a hint?

Call .Split(separator) on employeeData and assign it to employeeList.

4
Clean the employee names
Use a foreach loop to go through employeeList. Inside the loop, use .Trim() to remove spaces and .Replace() to fix the typo "Bob Johnson" to "Robert Johnson". Store the cleaned names in a new array called cleanedList
PowerShell
Need a hint?

Use $cleanName = $employee.Trim() to remove spaces. Use .Replace() only if the name is "Bob Johnson".

5
Print the cleaned employee list
Use Write-Output to print each name in cleanedList on a new line
PowerShell
Need a hint?

Use a foreach loop and Write-Output to print each name.