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, cherryChallenge
EasyWrite 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.
Try it yourself
using System;
class Program {
public static void Main(String[] args) {
// Write code here
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3