Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ASCII Value of a character
Message
De
14/09/2005 12:33:48
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01049249
Message ID:
01049521
Vues:
14
Your code doesn't validate a time string (except checking allowable chars - assuming there were no typo). Here is a code that would validate a time string - time part only:
  private static bool IsTimeString(string sTime)
  {
   bool bValid = true;
   try
   {
     DateTime.Parse("1/1/2000 "+sTime);
   } 
   catch
   {
     bValid = false;
   }
   return bValid;
 }
Cetin

>Sorry, I misunderstood what you said.
>
>This solution works fine. Thank you
>
>
>
>>Kevin,
>>You asked how to convert char (unicode) to byte. But substring returns a string.
>>System.Text.Encoding.ASCII.GetBytes(sString) would return a byte[].
>>As I see you need it to validate a time string. Then you might instead directly use DateTime class' Parse.
>>Cetin
>>
>>>Not sure why this doesn't work. ascVal contains the character
>>>from the substring.
>>>
>>>Here's my code:
>>>
>>>
>>>for(int iChar = 1; iChar < sTime.Length; iChar++)
>>>{
>>>  sChar = sTime.Substring(iChar - 1, 1);
>>>
>>>  byte ascVal = System.Convert.ToByte(sChar);
>>>
>>>  // Allowable values are 0-9,';','A','M','P'
>>>  if ((iValue >= 48 && iValue <= 57) ||
>>>    iValue == 58 ||
>>>    iValue == 59 ||
>>>    iValue == 77 ||
>>>    iValue == 80)
>>>  {
>>>  }
>>>  else
>>>    bValid = false;
>>>
>>>}
>>>
>>>
>>>
>>>
>>>
>>>
>>>>>I am extracting characters from a string.
>>>>>
>>>>>How can I determine the ASCII value of the characters?
>>>>>
>>>>>Thanks
>>>>
>>>>byte ascVal = System.Convert.ToByte(char);
>>>>
>>>>Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform