![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
c# Put spaces between words starting with capital letters
To place spaces in between words starting with capital letters, try the following example −
Firstly, set the string.
var str = "WelcomeToMyWebsite";
As you can see above, our string isn’t having spaces before capital letter. To add it, use LINQ as we have done below −
str = string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
The following is the complete code to place spaces between words beginning with capital letters −
Example
using System; using System.Linq; class Demo { static void Main() { var str = "WelcomeToMyWebsite"; Console.WriteLine("Original String: "+str); str = string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' '); Console.WriteLine("New String: "+str); Console.ReadLine(); } }
Advertisements