#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    3
    Rep Power
    0

    Regular expression question


    I would like to convert a string in the form
    "ThisIsATest" to a sting in the form of " this is a test".

    Basically all characters that are capitol should be converted to lowercase and given a leading space.

    Using the Regex.Replace method, how would you complete this?

    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Redmond, WA
    Posts
    218
    Rep Power
    18
    Code:
    using System;
    using System.Text.RegularExpressions;
    
    public class RegexExample {
    	
    	public static void Main() {
    		
    		Regex regex = new Regex( "(?<capitalLetter>[A-Z])" );
    		string str = "thisIsAString";
    
    		if ( regex.IsMatch( str ) ) {
    			Console.WriteLine( regex.Replace( str, " ${capitalLetter}" ).ToLower() );
    		}
    
    	}
    
    }

IMN logo majestic logo threadwatch logo seochat tools logo