check an phone number area code with strncmp

조회 수: 1 (최근 30일)
jarvan
jarvan 2014년 11월 18일
댓글: Guillaume 2014년 11월 18일
The phone number should be ###-###-####, which is including the dash. I am writing a function to determine whether a string form a phone format and a right area code checking for a three character combination followed by a dash. however, if I put dash in the string, it means to subtract. How can I avoid that?
function y = areacode(pnumber)
usernum = input('Enter your number with dash : ' )
if strncmp(pnumber,usernum,4)== 1
disp('The area code is same!')
else
disp('The area code is not same.')
end
end

채택된 답변

Phillip
Phillip 2014년 11월 18일
Hi
Type
help input
at the command prompt and have a look at what it says. Your answer is right there.
Regards, Phil
  댓글 수: 2
jarvan
jarvan 2014년 11월 18일
i should put in '' to avoid it ,thank you
Guillaume
Guillaume 2014년 11월 18일
You should put in 's' as in
input('enter your number', 's')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by