Extract words between characters.

Im trying to copy words from item.txt file and put them into an index matrix (show me the location of each word), copy the entire string between a bunch of characters and store the string into one matrix.
I already have a program that do something similar, the results of the following program is attached into "results.jpg".
What i want now is to copy the words between the characters "//================..." and store each word into a matrix . The first result would be the word "Blink dagger". The words between "//================..." are always different. The file "items.txt" is also attached.
// DOTA_ABILITY_BEHAVIOR_DIRECTIONAL = 1024 : This ability has a direction from the hero
// DOTA_ABILITY_BEHAVIOR_IMMEDIATE = 2048 : This ability does not interrupt other abilities
//
//=================================================================================================================
// Blink dagger
//=================================================================================================================
"item_blink"
{
// General
//-------------------------------------------------------------------------------------------------------------
-
function x=item_dota()
fid = fopen('items.txt') ;
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
idx = strfind(S, '"ItemCost"');
idx = find(not(cellfun('isempty',idx)));
ACD = S(idx);
b=regexp(ACD,'\d+(\.)?(\d+)?','match');
iwant=str2double([b{:}]);
y=size(iwant);
end

 Respuesta aceptada

per isakson
per isakson el 15 de Dic. de 2016
Editada: per isakson el 15 de Dic. de 2016
This is one way with regexp
str = fileread('items.txt');
xpr = '(?://=+\s*//\s)(.+)(?:\s*//=+\r\n)';
cac = regexp( str, xpr, 'tokens', 'dotexceptnewline' );
cac = strtrim(cac);
check result
>> cac{1}{:}
ans =
Blink dagger
>> cac{2}{:}
ans =
Blades of Attack
>> cac{3}{:}
ans =
Broadsword
>> cac{200}{:}
ans =
Recipe: Diffusal Blade
>> cac{245}{:}
ans =
RiverPainter7
>>
and peel off some braces.

Más respuestas (0)

Categorías

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

Etiquetas

Preguntada:

el 15 de Dic. de 2016

Comentada:

el 16 de Dic. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by