|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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() );
}
}
}
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Regular expression question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|