Click here to Skip to main content
15,917,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quick Question, I have something that I would like to implement a custom format string on like the Date/Time Object one. Basically, I just need it to find %P and replace it with something. Although, it would be great if I could easily expand it for other things. I found an article on MSDN but, I didn't make heads or tales of it. So if anyone could provide me with a sample or point me in the right direction, I'd 'preciate it!

Thanks!
M
Posted

Use a Regex:
VB
Public Dim regex As Regex = New Regex( _
      "(%P)", _
    RegexOptions.IgnoreCase _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
    )
Public Dim regexReplace As String = _
      "percentP"

Dim result As String = regex.Replace(InputText,regexReplace)


Have a look at Expresso [^]- creates, examines and explains regex strings. And it's free.
 
Share this answer
 
While Griff's solution is appropriate, I'm not a big fan of Regex, so I would approach it this way:

myString = myString.Replace("%P", replacementString);


That's a LOT less code, a LOT faster than Regex will ever be, and consumes fewer resources besides.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900