我讨厌问这个问题,但是我非常接近搞清楚,这真的很困扰我。我需要将我的字符串切换为camelcase。我摆脱了空间,我可以大写正确的字母,我可以删除元音,但我需要保留代码的第一个字母,我似乎无法让它留下来。我试过用六种不同的方式对它进行索引,但无济于事。
function[cameltoe] = abbreviatingCamelCase(firstWord)
indexing = find(firstWord(1:end - 1) == ' ');%I want to find all the spaces here
firstWord( indexing + 1) = upper(firstWord(indexing + 1)); %I want to uppercase all the words following a space
firstWord(firstWord == ' ') = [];
firstWord(ismember(firstWord, ' aeiou')) = [];
cameltoe = firstWord;
'一条鱼两条鱼红鱼蓝鱼'应该变成'onFshTwFshRdFshBlFsh'。我一直在研究这个问题至少两个小时。我尝试将'aeiou'所在的第一个索引编入索引,但这似乎不起作用。
答案 0 :(得分:1)
希望你不介意我创建了一个额外的变量。这是你在找什么?
firstWord = 'one fish two fish red fish blue fish'
indexing = find(firstWord(1:end - 1) == ' ');%I want to find all the spaces here
firstWord( indexing + 1) = upper(firstWord(indexing + 1)); %I want to uppercase all the words following a space
firstWord(firstWord == ' ') = [];
Li = ismember(firstWord, 'aeiou');
Li(find(Li,1,'first'))=0;
firstWord(Li) = [];
cameltoe = firstWord
编辑:如果你想保留第一个字母,不管是否是元音:
indexing = find(firstWord(1:end - 1) == ' ');
firstWord( indexing + 1) = upper(firstWord(indexing + 1));
firstWord(firstWord == ' ') = [];
firstWord([false ismember(firstWord(2:end), 'aeiou')]) = [];
cameltoe = firstWord;