Thread Subject: reading a value in a string

Subject: reading a value in a string

From: Nhan Nguyen

Date: 10 Feb, 2010 01:09:05

Message: 1 of 2

lets say I got a string C = "this is for testing1", how do I get that value 1 in that string into an integer? I know I can find the length(C) then what? There's fgets and fread but I don't know how to setup those functions up to find that value 1 at the end of that string.

Subject: reading a value in a string

From: ade77

Date: 10 Feb, 2010 01:43:04

Message: 2 of 2

"Nhan Nguyen" <nepthonius@gmail.com> wrote in message <hkt0vh$ko9$1@fred.mathworks.com>...
> lets say I got a string C = "this is for testing1", how do I get that value 1 in that string into an integer? I know I can find the length(C) then what? There's fgets and fread but I don't know how to setup those functions up to find that value 1 at the end of that string.

For your specific example:
C = 'this is for testing1'
h = C(end)
answer = str2num(h)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com