Home > front end >  Convert a entire string value into ASCII number in Asp.Net Core
Convert a entire string value into ASCII number in Asp.Net Core

Time:08-12

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.

CodePudding user response:

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.

  • Related