Menu
Coddy logo textTech

String Methods Part 2

Part of the Fundamentals section of Coddy's C# journey — lesson 62 of 69.

Use string.Join() to combine array elements into a single string.

Example:

string[] words = { "Hello", "World", "C#" };
string result = string.Join(" ", words);
Console.WriteLine(result);
// Output: Hello World C#

Use .Split() to divide a string into substrings based on a delimiter.

Example:

string text = "apple banana cherry";
string[] fruits = text.Split(' ');
Console.WriteLine(string.Join(", ", fruits));
// Output: apple, banana, cherry
challenge icon

Challenge

Easy

Write a program that takes two inputs: a text string and a delimiter character. The program should replace all single spaces (" ") in the text with the specified delimiter and print the modified string.

Cheat sheet

Use string.Join() to combine array elements into a single string:

string[] words = { "Hello", "World", "C#" };
string result = string.Join(" ", words);
// Output: Hello World C#

Use .Split() to divide a string into substrings based on a delimiter:

string text = "apple banana cherry";
string[] fruits = text.Split(' ');
// Output: apple, banana, cherry

Try it yourself

using System;

class Program {
    public static void Main(String[] args) {
        // Write code here
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals