Aniket Narvankar

Aniket Narvankar

  • 562
  • 2.1k
  • 604.9k

How to Replace Substring with Take,Skip in Linq

Dec 3 2021 5:07 AM
class phoneNumber
{       
        /*Returns phoneNum after spliting*/
        public string splitPhone(string phoneNum)
        {
           if(phoneNum.Length > 9 && phoneNum.Substring(0,1)=="1")
            {
                phoneNum = phoneNum.Substring(1,9);
            }
           return phoneNum;
        }
        /*returns phone prefix*/
        public string phonePrefix(string phoneNum)
        {
             if(phoneNum.Length > 7)
             {
               phoneNum.Substring(0,3);
             }
             return phoneNum;
        }
        /*returns phone suffix*/
        public string phoneSuffix(string phoneNum)
        {
             if(phoneNum.Length > 7)
             {
              phoneNum.Substring(3,7);
             }
            return phoneNum;
        }
     }
   }
}

First method splitPhone splits phoneNumber,second method phonePrefix returns phonePrefix,third method phoneSuffix returns phoneSuffix. How to replace Substring function in this methods with take and skip. Want to write this same code using take,skip in c sharp. please let me know how this could be done


Answers (3)