strings

조회 수: 14 (최근 30일)
Dylan
Dylan 2011년 12월 7일
clear
clc
word=lower(double(input('Enter a character \n')));
letter = char(input('Guess a character : ','s'));
stat = findstr(word,letter);
I'm trying to get the user to enter any number of character(not case sensitive). Then enter any random character and see if it matches any character of their first input.
  댓글 수: 2
Chandra Kurniawan
Chandra Kurniawan 2011년 12월 7일
What are you trying todo??
You said that 'trying to get the user to enter any number'.
But your code :
word=lower(double(input('Enter a character \n')));
Now, how can I use command 'lower' with numerical (double) input??
command lower works only for string, right??
Chris
Chris 2011년 12월 7일
I thought lower was to not make it not case sensitive. And I'm trying to get the user to any character, not just numbers.

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

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 7일
Did you mean??
clear; clc;
word = lower(input('Enter a word : ','s'));
letter = input('Guess a character : ','s');
stat = findstr(word,letter);
if ~isempty(stat)
for x = 1 : length(stat)
fprintf('Character %c macthes with word %s in column %d\n',letter,word,stat(x));
end
else
fprintf('Character %c no found in word %s\n',letter,word);
end
  댓글 수: 1
Dylan
Dylan 2011년 12월 7일
Yep, exactly what I meant, thank you!

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

추가 답변 (1개)

Sven Schoeberichts
Sven Schoeberichts 2011년 12월 7일
word = input('Enter a word: ', 's');
letter = input('Guess a character : ','s');
stat = ismember(letter,lower(word));
stat = 1: character is present in word
stat = 0: character is not present in word
  댓글 수: 1
Dylan
Dylan 2011년 12월 7일
Okay, I may should have been more specific. Suppose the word I input is loop. And I guess the letter o. I expect a return of 0 1 1 0. 1 representing the number of times o is in the word.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by