Click here to Skip to main content
15,891,204 members
Articles / Programming Languages / XML
Alternative
Tip/Trick

.Net - Use The Framework

Rate me:
Please Sign up or sign in to vote.
2.33/5 (9 votes)
6 Apr 2010CPOL 8.1K   2   6
The following is far easier to understand and use than the Outlaw's tip (IMHO).text = Regex.Replace(text, "screen_fadetimeout=\"[^\"\']+\"", "screen_fatetimeout="99");It has the following advantages:1. It is one line of code2. It is easier to read3. It is faster (note: XmlElement...
The following is far easier to understand and use than the Outlaw's tip (IMHO).

text = Regex.Replace(text, "screen_fadetimeout=\"[^\"\']+\"", "screen_fatetimeout="99");


It has the following advantages:
1. It is one line of code
2. It is easier to read
3. It is faster (note: XmlElement uses Regex in it's implementation) and further speed can be gained by using a compiled Regex instance.
4. No need to worry about null references (what if the desired element doesn't exist?)
5. It is light compared to XmlElement.Parse()
6. If you need to know if the item was found, you can use the MatchEvaluator overload and an anonymous delegate -- still one line of code.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 4 4 - I see nothing wrong in your solu... Pin
johannesnestler24-Feb-12 0:56
johannesnestler24-Feb-12 0:56 
GeneralRe: Reason for my vote of 44 - I see nothing wrong in your solu... Pin
TheGreatAndPowerfulOz8-Mar-17 15:35
TheGreatAndPowerfulOz8-Mar-17 15:35 
GeneralReason for my vote of 2 Isn't you find John Simmons's way wi... Pin
Pranit Kothari8-Jan-12 4:20
Pranit Kothari8-Jan-12 4:20 
GeneralRe: Reason for my vote of 2Isn't you find John Simmons's way wi... Pin
TheGreatAndPowerfulOz8-Mar-17 15:38
TheGreatAndPowerfulOz8-Mar-17 15:38 
GeneralIt's not about what I did - it's about why I did it. Pin
#realJSOP22-May-10 3:14
mve#realJSOP22-May-10 3:14 
GeneralRe: It's not about what I did - it's about why I did it. Pin
TheGreatAndPowerfulOz8-Mar-17 15:36
TheGreatAndPowerfulOz8-Mar-17 15:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.