Get values within string with special characters
6 次查看(过去 30 天)
显示 更早的评论
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
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
2023-4-12
One more hint
str = sprintf("\n\n*58477$265#"); % sample data
extractBetween( str, "*", "$" )
extractBetween( str, "$", "#" )
and it's nothing wrong with loops if your column isn't HUGE and execution time becomes a problem.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!