Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Removing part of string

Subject: Removing part of string

From: Victoria Emberle

Date: 17 Dec, 2010 18:57:04

Message: 1 of 5

Hello,

I have numerous strings that are mostly different but follow the same format .
For example
'1.2.3.4.209807.54'

basically I want the section 209807 of each string.
This is my code
for i=1:NumbImgsCT
 dummy=Imgs.CT(i).Tags.SOPInstanceUID
  dummy2=find(dummy=='.')
    dummy3=dummy(max(dummy2)+1:length(dummy))

this gives me code gives me
209807.54

but I want .54 removed

I want 209807

Please can you help

Subject: Removing part of string

From: Sean de

Date: 17 Dec, 2010 19:05:06

Message: 2 of 5

"Victoria Emberle" <emberley@uvic.ca> wrote in message <iegbq0$lop$1@fred.mathworks.com>...
> Hello,
>
> I have numerous strings that are mostly different but follow the same format .
> For example
> '1.2.3.4.209807.54'
>
> basically I want the section 209807 of each string.

%%
str = '1.2.3.4.209807.54';
idx = strfind(str,'.'); % or idx = find(str=='.');
str(idx(4)+1:idx(5)-1)

Subject: Removing part of string

From: Matt Fig

Date: 17 Dec, 2010 19:29:05

Message: 3 of 5

Also,

str = '1.2.3.4.209807.54'; % Given string
regexp(str,'(?<=\.)(\d{3,})+(?=\.)','match')

Subject: Removing part of string

From: Jan Simon

Date: 17 Dec, 2010 19:39:06

Message: 4 of 5

Dear Victoria,

S = '1.2.3.4.209807.54'
N = sscanf(S, '%d.')
% N = [1; 2; 3; 4; 209807; 54]
Result = N(5)

Jan

Subject: Removing part of string

From: Walter Roberson

Date: 17 Dec, 2010 20:05:10

Message: 5 of 5

On 10-12-17 12:57 PM, Victoria Emberle wrote:

> I have numerous strings that are mostly different but follow the same format .
> For example
> '1.2.3.4.209807.54'
>
> basically I want the section 209807 of each string.
> This is my code
> for i=1:NumbImgsCT
> dummy=Imgs.CT(i).Tags.SOPInstanceUID dummy2=find(dummy=='.')
> dummy3=dummy(max(dummy2)+1:length(dummy))
>
> this gives me code gives me 209807.54
>
> but I want .54 removed
>
> I want 209807

In addition to the other good responses you have already received: you could use

fix(str2double(dummy3))

which would give you the *number* 209807

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us