473,395 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Create a function like IsDigit()

Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);

Sam
Jan 11 '08 #1
16 7225
Hi,

sk*****@gmail.com schrieb:
Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);

Sam
do you mean digit like '0', '1', .. '9', which is a (or better nine)
simple equal operations, or number? If, which numbers? int, double?

Sounds like homework ;)

Tobi
Jan 11 '08 #2
You can use int.TryParse or check that each character in the strign is
a digit:

foreach(char c in string s)
if !char.IsDigit(c)
return false

return true;

Calum.

On Jan 11, 1:09 pm, skne...@gmail.com wrote:
Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);

Sam
Jan 11 '08 #3
sk*****@gmail.com wrote:
Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);
Use a regular expression. Something simple like "[0-9]+" should work.

Chris.
Jan 11 '08 #4
Do you mean:
if(!char.IsDigit(c)) return false;

[which might actually answer the OP on its own]

Marc
Jan 11 '08 #5
Hello Chris,
sk*****@gmail.com wrote:
>Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);
Use a regular expression. Something simple like "[0-9]+" should work.

Chris.
int val = 0;
return int.TryParse(stringInput, NumberStyles.Integer, val);

should work (though I don't have intellisense in my newsreader ;)) and should
be much faster than a regex.
--
Jesse Houwing
jesse.houwing at sogeti.nl
Jan 11 '08 #6
Hi,

What about:

bool MyIsDigit(string s)
{
return IsDigit(s);
}
:-)

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

<sk*****@gmail.comwrote in message
news:c6**********************************@n20g2000 hsh.googlegroups.com...
Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);

Sam

Jan 11 '08 #7
<sk*****@gmail.comwrote in message
news:c6**********************************@n20g2000 hsh.googlegroups.com...
Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);

Sam
Sounds like 101 lesson 1.
We should not do your homework for you.
If this is a problem for you, you really need 'Programming for Dummies'

- Michael Starberg
Jan 11 '08 #8
On 11 jan, 14:22, Chris Shepherd <c...@nospam.chsh.cawrote:
Use a regular expression. Something simple like "[0-9]+" should work.
Very good suggestion !
Thanks a lot for all.

Sam
Jan 11 '08 #9
On Fri, 11 Jan 2008 08:22:19 -0500, Chris Shepherd
<ch**@nospam.chsh.cawrote:
>sk*****@gmail.com wrote:
>Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);

Use a regular expression. Something simple like "[0-9]+" should work.

Chris.
<mode="pedant">
That does not work for all languages using non-Roman alphabets. For
example Arabic (?????), Unicode U+0660 on, or devanagari (?????),
Unicode U+0966 on, have their own sets of digits. The question is not
specified sufficiently clearly to determine if your answer is
sufficient or not.
</mode>

rossum

Jan 11 '08 #10
"rossum" <ro******@coldmail.comwrote in message
news:sj********************************@4ax.com...

<mode="pedant" />

LOL
Jan 11 '08 #11
rossum wrote:
<mode="pedant">
That does not work for all languages using non-Roman alphabets. For
example Arabic (?????), Unicode U+0660 on, or devanagari (?????),
Unicode U+0966 on, have their own sets of digits. The question is not
specified sufficiently clearly to determine if your answer is
sufficient or not.
</mode>
LOL@<mode="pedant" />, but I hardly call that being pedantic. It's very true, if
the OP is parsing non-Arabic numbering, it will be an issue.

Chris.
Jan 11 '08 #12

"Chris Shepherd" <ch**@nospam.chsh.cawrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
rossum wrote:
><mode="pedant">
That does not work for all languages using non-Roman alphabets. For
example Arabic (?????), Unicode U+0660 on, or devanagari (?????),
Unicode U+0966 on, have their own sets of digits. The question is not
specified sufficiently clearly to determine if your answer is
sufficient or not.
</mode>

LOL@<mode="pedant" />, but I hardly call that being pedantic. It's very
true, if the OP is parsing non-Arabic numbering, it will be an issue.

Chris.
I am not sure what you laughed about, but for me it was the non-valid xml.

<element attribute="value" />

Rossum is a sloppy pedant =)

- Michael Starberg
Jan 11 '08 #13
On Fri, 11 Jan 2008 12:34:31 -0800, Michael Starberg
<mi***************************@gmail.comwrote:
I am not sure what you laughed about, but for me it was the non-valid
xml.
How do you know it was supposed to be XML?

Maybe he's just using a markup that happens to be similar to XML, but
which has its own rules. For all you know, the markup he used could be
perfectly valid when interpreted correctly.
Jan 12 '08 #14
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Fri, 11 Jan 2008 12:34:31 -0800, Michael Starberg
<mi***************************@gmail.comwrote:
>I am not sure what you laughed about, but for me it was the non-valid
xml.

How do you know it was supposed to be XML?

Maybe he's just using a markup that happens to be similar to XML, but
which has its own rules. For all you know, the markup he used could be
perfectly valid when interpreted correctly.
Maybe...
Jan 12 '08 #15
On 12 Jan, 06:11, "Michael Starberg" <michael.spam-
captcha.starb...@gmail.comwrote:
"Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote in message

news:op***************@petes-computer.local...
On Fri, 11 Jan 2008 12:34:31 -0800, Michael Starberg
<michael.spam-captcha.starb...@gmail.comwrote:
I am not sure what you laughed about, but for me it was the non-valid
xml.
How do you know it was supposed to be XML?
Maybe he's just using a markup that happens to be similar to XML, but
which has its own rules. *For all you know, the markup he used could be
perfectly valid when interpreted correctly.

Maybe...
Oh, yeah.. I love the way thease threads go sometimes..
//CY
Jan 14 '08 #16
rossum wrote:
On Fri, 11 Jan 2008 08:22:19 -0500, Chris Shepherd
<ch**@nospam.chsh.cawrote:
>sk*****@gmail.com wrote:
>>Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);
Use a regular expression. Something simple like "[0-9]+" should work.

Chris.
<mode="pedant">
That does not work for all languages using non-Roman alphabets. For
example Arabic (?????), Unicode U+0660 on, or devanagari (?????),
Unicode U+0966 on, have their own sets of digits. The question is not
specified sufficiently clearly to determine if your answer is
sufficient or not.
</mode>

rossum
Additionally, a "digit" is one digit, not a sequence of them, that's a
number.

I'd say the OP is either looking for a homework answer, or he's looking
for Int32.TryParse.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jan 14 '08 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: deko | last post by:
I have 3 files I need to write to - and need to make sure I have a lock on each, and take action if I can't get a lock. The code below works, but I know it could be more efficient if I used a...
5
by: Thomas LeBlanc | last post by:
I copied an example from the help: CREATE FUNCTION somefunc() RETURNS integer AS ' DECLARE quantity integer := 30; BEGIN RAISE NOTICE ''Quantity here is %'', quantity; -- Quantity here is 30...
1
by: Barbara Lindsey | last post by:
I am a postgres newbie. I am trying to create a trigger that will put a copy of a record into a backup table before update or delete. As I understand it, in order to do this I must have a...
5
by: Bob Stearns | last post by:
I don't understand the following error: DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned:...
1
by: Frank Neubert | last post by:
Hello! I work with "IBM DB 2 Universal Database for Windows NT" Version 6. I want to create Function, which are using in a Queries. I don't want to use external function. I want to create a...
13
by: invincible | last post by:
hi friends , how can I declare / create function during runtime similiar to lambda in lisp. thanks Mohan
4
by: Markus Bertheau | last post by:
Hi, why does everyone write CREATE FUNCTION foo() RETURNS INTEGER AS ' blah blah ' LANGUAGE 'plpgsql'; I've never seen for example:
2
by: Jiri Nemec | last post by:
Hello all, sorry about beginner question, but I'm sure function has correct structure, buw PostgreSQL reports error. (This function is only on approbation.) CREATE FUNCTION foo(int2) RETURNS...
0
by: bog39 | last post by:
We have z/os and DB/2 V. 8 running. I try to create a new UDF using the command CREATE FUNCTION: CREATE FUNCTION CNGETADR (INTEGER) RETURNS CHAR(50) EXTERNAL NAME CNADR001 ...
6
japuentem
by: japuentem | last post by:
throwing error when creating function DB21034E DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.