How to cut the end of a string which follows a special character?

For example: 'sahdklsjf_sdfs' to 'sahdklsjf'

2 comentarios

The following is not working for me: source = mfilename(1:end-5) Why? But this works: source = mfilename source = source(1:end-5) Why?
mfilename is a function, so it can't be indexed. Assigning its result to a variable then gives you a string which can be indexed.

Iniciar sesión para comentar.

Respuestas (3)

Many options, including:
str = 'sahdklsjf_sdfs'
out1 = str(1:find([str '_']=='_',1,'first'))
Also take a look at TEXTSCAN

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Mayo de 2015

Respondida:

el 26 de Mayo de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by