🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7579

Re: check a string format

#7579
From: Remy Lebeau (TeamB)
Date: Thu, 20 Jan 2005 20:49
25 lines
1568 bytes
"DaniD" <together24@yahoo.com> wrote in message
news:41efeefa@newsgroups.borland.com...

> How can I check if a String has a format such as "hh:mm"?

(untested):

    AnsiString string = "02:00";
    short hour, minutes;
    if( sscanf(string.c_str(), "%02hd:%02hd", &hour, &minutes) != 2 )
    {
        if( (hour < 1) || (hour > 23) || (minutes < 0) || (minutes > 59) )
            // wrong format
    }
    else
        // wrong format

> I want to be able to check if the inserted time is right.

You could alternative just assign the string to a TDateTime and see if the
conversion fails.


Gambit
Technical Details
Message-ID: <41f018e1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41efeefa@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,75a5742ba1befd01
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41efeefa@newsgroups.borland.com>
Subject: Re: check a string format
Date: Thu, 20 Jan 2005 12:49:54 -0800
Lines: 27
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <41f018e1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1106254049 68.69.17.41 (20 Jan 2005 12:47:29 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail