[Logo]
Forums Register Login
Find special characters in string (Performance)
Hello Guys,
I need to create a method that determines if certain characters like


Which of this two ways is better in performance? Or is there any better way?


Thanks
Martin
[ April 03, 2006: Message edited by: Martin Lira ]
If no special characters are present, the first method will scan the whole string four times, while the second will only scan it once. Performance-wise, that's the only difference worth noticing, so you might as well go with the second method. But you're probably wasting your effort. Remember the three rules of optimization:

1. Don't do it.
2. Don't do it.
3. Before you do it, complete the app and profile it; the bottlenecks probably aren't where you expect them to be.
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS


This thread has been viewed 7548 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 23, 2018 23:21:40.