How can I trim these strings according to the underscores

3 views (last 30 days)
I need to trim these strings according to the underscores, basically from every string I need to obtain 5 pieces
Novana_Model_B180_DK1_4284.0
Novana_Model_ALSTED_AA_DK1_7835.166666666666
Novana_model_Storaa_DK3_11535.0
DK_QNP_Aa51200001_DK3_1469.143
Novana_Model_MOELLERENDE_DK1_492.42857142857144
DK_QNP_Aa51200001_DK3_979.429
Novana_Model_MOELLERENDE_DK1_984.8571428571429
DK_QNP_Aa51200062_DK3_1961.2
DK_QNP_Aa51200062_DK3_4412.7
DK_QNP_Aa51200062_DK3_2451.5
Novana_model_Branch_73_DK3_1263.75
DK_QNP_Aa51200062_DK3_4412.7
Novana_model_Branch_73_DK3_1263.75
  2 Comments
Chiara Scarpellini
Chiara Scarpellini on 26 Jul 2021
What if I want now to merge the part before the DK and keep the numbers at the end separated?
NovanaModelB180 4284.0
NovanaModelALSTEDAA 7835.166666666666

Sign in to comment.

Accepted Answer

Chunru
Chunru on 25 Jul 2021
Edited: Chunru on 26 Jul 2021
str = "Novana_Model_B180_DK1_4284.0"
str = "Novana_Model_B180_DK1_4284.0"
str1 = strsplit(str, '_')
str1 = 1×5 string array
"Novana" "Model" "B180" "DK1" "4284.0"
join(str1(1:4), '')
ans = "NovanaModelB180DK1"

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!