필터 지우기
필터 지우기

Get values within string with special characters

조회 수: 5 (최근 30일)
Wookie
Wookie 2023년 4월 12일
이동: dpb 2023년 4월 12일
Hi all,
I have a column of strings such as these. My desired output will be two columns for each respective set of numbers
"
*58477$265#"
It's newline, new line and an asterisk. I am trying to get both sets of numbers (between *..$ and $..#). I could not get sscanf or extractAfter to work for this case. Any suggestions?
  댓글 수: 5
Walter Roberson
Walter Roberson 2023년 4월 12일
Note: textscan() can only handle a string scalar or a character vector (not a character array), so it cannot directly be used in this situation, at least not without looping or arrayfun()... though you could potentially join() the strings to make one long string that you could process with textscan()
per isakson
per isakson 2023년 4월 12일
One more hint
str = sprintf("\n\n*58477$265#"); % sample data
extractBetween( str, "*", "$" )
ans = "58477"
extractBetween( str, "$", "#" )
ans = "265"
and it's nothing wrong with loops if your column isn't HUGE and execution time becomes a problem.

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2023년 4월 12일
이동: dpb 2023년 4월 12일
str = sprintf("\n\n*58477$265#"); % sample data
str = [str;str];
Carrying on in the same vein with some of the newer stuff...
str2double(extract(str,digitsPattern))
ans = 2×2
58477 265 58477 265

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by