Refer to the character ' in a string
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, i'm trying to write an algorithm to remove the character ' from a string, say for example: string='you're';
where I want to remove the ' to make the string 'youre' I get errors when I try to refer to a character as ''' though,
is there something I'm missing?
2 commentaires
Steven Lord
le 25 Jan 2023
This wasn't an option when the question was originally asked, but if you're using string arrays you don't need to double up the single quotes.
s = "you're"
t1 = strrep(s, "'", "")
t2 = erase(s, "'")
t3 = replace(s, "'", "")
Réponses (1)
Walter Roberson
le 31 Mar 2013
string(string == '''') = '';
3 commentaires
Image Analyst
le 31 Mar 2013
Modifié(e) : Image Analyst
le 31 Mar 2013
Why do it that way, which is dependent on the apostrophe being in the 4th position rather than the more general way Walter suggested? Heck if you're going to assume that, then you might as well do
a(4) = [];
or
a = [a(1:3), a(5:end)];
Perhaps what you were trying to do is this:
apostrophe = ''''
a= ['you', apostrophe, 're']
quoteLocation = strfind(a, apostrophe)
apostrophe =
'
a =
you're
quoteLocation =
4
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!