フィルターのクリア

Textscan: How to skip a delimiter present within single quotes

3 ビュー (過去 30 日間)
Farook Sadarudeen
Farook Sadarudeen 2020 年 5 月 1 日
コメント済み: Stephen23 2020 年 5 月 1 日
During testscan I am using semicolin(;) as delimiter but I want to skip this delimiter if it is present within single quotes.
How can I do it?
Example,
string1 = string2 ; xyz.data = 'string3(1 = string4; 0 = string5)' ; sring6;
Expected output: Semicolon inside value to need to be skipped
value1 => string1 = string2
value2 => xyz.data = 'string3(1 = string4; 0 = string5)'
value3 => sring6

回答 (1 件)

Stephen23
Stephen23 2020 年 5 月 1 日
>> str = fileread('test.txt')
str =
string1 = string2 ; xyz.data = 'string3(1 = string4; 0 = string5)' ; sring6;
>> out = textscan(strrep(str,'''','"'),'%q%q%q','delimiter',';');
>> out{:}
ans =
'string1 = string2 '
ans =
'xyz.data = "string3(1 = string4; 0 = string5) '
ans =
'sring6'
  2 件のコメント
Farook Sadarudeen
Farook Sadarudeen 2020 年 5 月 1 日
Thanks for your answer. Number of substring is dynamic in my case. I have mentioned 3 in my case but it can vary in each line of my file.
Stephen23
Stephen23 2020 年 5 月 1 日
"I have mentioned 3 in my case but it can vary in each line of my file"
textscan might not be the best tool for this. Please upload a sample file by clicking the paperclip button.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by