Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert a entire string value into ASCII number in Asp.Net Core

I need to convert the entered string value into a a ASCII value to store into DB as an array objects. It is required as per the functional requirement.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the below code –

public int[] convertStringToASCII(string value)
{
   
    int[] result;  
    string str=String.Empty;  
    foreach(var c in value)  
    {  
         if(char.IsDigit(c))  
         {  
             result.add(Convert.ToInt32(c)); 
         }
         else
         {  
            result.add((int)c);  
         }  
     }  
     return result;
}

The else part was added due to consider if the string value contains any numerical value. Hope it will solve ur problems.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading