String 在字符串中的任意位置查找具有特定模式的子字符串

String 在字符串中的任意位置查找具有特定模式的子字符串,string,matlab,find,String,Matlab,Find,我从我们的设备阵列中获得了许多字符串。有两种不同类型的字符串: 011_c_srr_Rtzfi_at000_hh5_fs_v343_l067_i1_测试 041A CdDDRZrFixDS000 0HH55FSYV33L037 I1TestTEL霍尔需要的信息在字符串的中间 061\u t\u err\u Rsas\u au000\u ti3\u fs\u v777\u l011\u 021\u t\u err\u Rsas\u au230\u ti3\u fs\u v777\u l031\u所

我从我们的设备阵列中获得了许多字符串。有两种不同类型的字符串:

011_c_srr_Rtzfi_at000_hh5_fs_v343_l067_i1_测试 041A CdDDRZrFixDS000 0HH55FSYV33L037 I1TestTEL霍尔需要的信息在字符串的中间 061\u t\u err\u Rsas\u au000\u ti3\u fs\u v777\u l011\u 021\u t\u err\u Rsas\u au230\u ti3\u fs\u v777\u l031\u所需信息位于字符串末尾 结论:我需要字符串l067/l037/l011的以下部分。。。。。例如,l067表示67%,I037表示37%。所以我需要这个百分之二的值。结果是67和37。 我的代码:只有部分

for j=1:numRows;
Name=LaSP.Messung(j, 1).name
Size=size(Name)
Length = strlength(Name)%Evaluiert die Länge des gesamten Strings
pos1 = findstr(Name, '_')%Listet alle "_" im String auf
[zeile1,spalte1]=size(pos1)
spalte=pos1(1,spalte1)%ich hol mir string position vom letzten "_"

if spalte==Length%Abfrage ob das letzte zeichen ist ein "_"
%%Abfrage ob der Wert schon einmal vorkam   
    %%die letzten 4 auslesen
else 
    %%in mitten des strings
end

      %pos = strfind(Name, '_')
 %k = strfind(Name,'_','ForceCellOutput',true)
 %idx = find(strcmp(Name, '_'))
 %pat='_';
%ind=regexp(Name,pat);
% word_to_find=strfind(strarray,'stringtofind');
% starray.index(word_to_find);
end
我的问题是我不能分割字符串。。。我无法提取最后4个字符。。。 感谢您

给出:

my_strings = {'011_c_srr_Rtzfi_at000_hh5_fs_v343_l067_i1_Test_Test',
'041_c_ddr_Rtzfi_ds000_hh5_fs_v343_l037_i1_Test_hall',
'061_t_err_Rsas_au000_ti3_fs_v777_l011_ *',
'021_t_err_Rsas_au230_ti3_fs_v777_l031_'};
这里几乎没有可能的解决方案

使用to match,我们可以构建模式来查找v后面的字符,后跟三位数字和下划线,例如v777_

使用在下划线上拆分,然后取第9个单元格:

split_strings = regexp(my_strings,'_','split');
matches = cellfun(@(x) x(9),split_strings).'
ans =

 1×4 cell array

 {'l067'}    {'l037'}    {'l011'}    {'l031'}
n = numel(my_strings);
matches = char.empty(0,n);
for i = 1:n
  split_string = strsplit(my_strings{i},'_');
  matches = [matches split_string(9)];
end
matches =

  1×4 cell array

  {'l067'}    {'l037'}    {'l011'}    {'l031'}
使用在下划线上拆分,然后取第9个单元格:

split_strings = regexp(my_strings,'_','split');
matches = cellfun(@(x) x(9),split_strings).'
ans =

 1×4 cell array

 {'l067'}    {'l037'}    {'l011'}    {'l031'}
n = numel(my_strings);
matches = char.empty(0,n);
for i = 1:n
  split_string = strsplit(my_strings{i},'_');
  matches = [matches split_string(9)];
end
matches =

  1×4 cell array

  {'l067'}    {'l037'}    {'l011'}    {'l031'}

您可能想访问常规表达感谢您发布了所需的输入输出和代码,但是代码有什么问题?你被卡住了吗?旁注:虽然不是不允许这样做,但使用德语的代码内注释会使非德语使用者更难理解。我会在仪表板上做一个strplit,然后抓住第九个牢房。你好,又问了一个问题。。。如果不是第九个牢房,我该怎么办?@FranzH哪一个牢房?这个数字只有9