Article View: borland.public.csharpbuilder.language.csharp
Article #354FindIntegerinStr
From: Jeff
Date: Mon, 14 Feb 2005 15:41
Date: Mon, 14 Feb 2005 15:41
34 lines
1751 bytes
1751 bytes
I am passing a sting to a function and trying to locate the position of
the first digit in the string, if there is one. In Delphi I had the
following:
function FrmLoad.LocateDigit(aPCode: string): Integer;
begin
for result := 1 to Length(aPCode) do
begin
if aPCode[result] in ['0'..'9'] then
Exit;
end;
result := 0;
end;
Here is what I have in C#:
private int LocateDigit(string aPCode)
{
int result = 0;
for(int i = 0; i<aPCode.Length; i++)
{
if (aPCode(result) in ["0".."9"]) ---This line errors
exit;
}
return int(result);
}
How would I accomplish the same in C#?
TIA
Technical Details
Message-ID:
<4210c68f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,66c7f96838fd6e37,start X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 14 Feb 2005 09:41:04 -0600 From: Jeff <jbarr62307@att.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.csharpbuilder.language.csharp Subject: FindIntegerinStr Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 12.240.53.183 Message-ID: <4210c68f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1108395663 12.240.53.183 (14 Feb 2005 07:41:03 -0800) Lines: 35 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail