hy,
i've got a simple question (for somebody who already knows the answer)
about regex:
i've a string like bla@bla@bla or bla@@bla
i like to check the @'s, but couldn't figure it out how to set zero or
more char's. (zero or one was easy).
thank's
rené
Aug 6 '07
14 2263
On Aug 7, 12:46 pm, "Kevin Spencer" <unclechut...@n othinks.comwrot e:
A string is an array of char. I believe the fastedst way would be to loop
through the chars in the string, and count the '@' chars. Once you reach 5,
you return true. If you reach the end of the string without reaching 5, you
return false.
Just to be clear: a string *isn't* an array of chars. It's a sequence
of characters, and there's a readonly indexer (as well as implementing
IEnumerable<cha r>) but it's not actually an array.
For example, you couldn't pass a string as an argument to a method
with a System.Array parameter.
Jon
On Aug 7, 10:19 am, ohmmega <sho...@gmx.atw rote:
i need this about 200 times in a time critical application, so i just
want to have the best option.
200 times in what space of time?
i've not measured the time yet, but that's a good point - i will try
this next.
That's definitely worth doing. In a little test application I wrote,
it took less than a second to check 2 *miilion* strings on my laptop.
Now, they were fairly short strings - you should test with real data -
but it's an indication.
Jon
Correct as usual, Jon. I should have said "a string encapsulates an array of
char, and can be treated just like one."
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:11******** *************@l 70g2000hse.goog legroups.com...
On Aug 7, 12:46 pm, "Kevin Spencer" <unclechut...@n othinks.comwrot e:
>A string is an array of char. I believe the fastedst way would be to loop through the chars in the string, and count the '@' chars. Once you reach 5, you return true. If you reach the end of the string without reaching 5, you return false.
Just to be clear: a string *isn't* an array of chars. It's a sequence
of characters, and there's a readonly indexer (as well as implementing
IEnumerable<cha r>) but it's not actually an array.
For example, you couldn't pass a string as an argument to a method
with a System.Array parameter.
Jon
On Aug 8, 12:17 pm, "Kevin Spencer" <unclechut...@n othinks.comwrot e:
Correct as usual, Jon. I should have said "a string encapsulates an array of
char, and can be treated just like one."
I think I'd still have quibbled: internally there isn't an array of
chars (unlike in Java, for instance) and you can't treat it as an
array of chars because you can always modify the contents of arrays,
whereas the string indexer is readonly.
There's always room for pedantry :)
Jon
Hi Jon,
I suppose pedantry has its place. These details are always useful to know.
In my case, I was simply talking about looping through the characters in the
string as an efficient way of counting the occurrences of a character.
However, it might have led to someone getting the wrong impression
concerning what ways one might be able to treat a string as if it were an
array of char. So, I don't take offense. I do think my solution was probably
the most efficient method for achieving the OP's goal, though. I hope that
the original problem has been solved.
--
HTH,
Kevin Spencer
Microsoft MVP
DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
On Aug 8, 12:17 pm, "Kevin Spencer" <unclechut...@n othinks.comwrot e:
>Correct as usual, Jon. I should have said "a string encapsulates an array of char, and can be treated just like one."
I think I'd still have quibbled: internally there isn't an array of
chars (unlike in Java, for instance) and you can't treat it as an
array of chars because you can always modify the contents of arrays,
whereas the string indexer is readonly.
There's always room for pedantry :)
Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jon Maz |
last post by:
Hi All,
Am getting frustrated trying to port the following (pretty simple) function
to CSharp. The problem is that I'm lousy at Regular Expressions....
//from http://support.microsoft.com/default.aspx?scid=kb;EN-US;246800
function fxnParseIt()
{
var sInputString = 'asp and database';
|
by: Tim Conner |
last post by:
Is there a way to write a faster function ?
public static bool IsNumber( char Value )
{
if (Regex.IsMatch( Value.ToString(), @"^+$" ))
{
return true;
}
else return false;
}
|
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex matches are called
within a loop (like if or for). E.g.
for(int i = 0; i < 10; i++)
{
Regex r = new Regex();
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
http://forta.com/books/0672325667/
|
by: Extremest |
last post by:
I have a huge regex setup going on. If I don't do each one by itself
instead of all in one it won't work for. Also would like to know if
there is a faster way tried to use string.replace with all the right
parts in there in one big line and for some reason that did not work
either. Here is my regex's.
static Regex rar = new Regex("\\.part.*",
RegexOptions.IgnoreCase);
static Regex par = new Regex("\\.vol.*",
RegexOptions.IgnoreCase);
| |
by: Extremest |
last post by:
I am using this regex.
static Regex paranthesis = new Regex("(\\d*/\\d*)",
RegexOptions.IgnoreCase);
it should find everything between parenthesis that have some numbers
onyl then a forward slash then some numbers. For some reason I am not
getting that. It won't work at all in 2.0
|
by: aspineux |
last post by:
My goal is to write a parser for these imaginary string from the SMTP
protocol, regarding RFC 821 and 1869.
I'm a little flexible with the BNF from these RFC :-)
Any comment ?
tests=
def RN(name, regex):
"""protect using () and give an optional name to a regex"""
if name:
|
by: morleyc |
last post by:
Hi, i would like to remove a number of characters from my string (\t
\r \n which are throughout the string), i know regex can do this but i
have no idea how. Any pointers much appreciated.
Chris
|
by: CJ |
last post by:
Is this the format to parse a string and return the value between the item?
Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>");
I am trying to parse this string.
<File_Name>Services</File_Name>
Thanks
|
by: Karch |
last post by:
I have these two methods that are chewing up a ton of CPU time in my
application. Does anyone have any suggestions on how to optimize them or
rewrite them without Regex? The most time-consuming operation by a long-shot
is the regex.Replace. Basically the only purpose of it is to remove spaces
between opening/closing tags and the element name. Surely there is a better
way.
private string FixupJavascript(string htmlCode)
{
string result...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |