Skip to content
Back to formatted view

Raw Message

Message-ID: <5934ae57050412233850ca8f7f@mail.gmail.com>
Date: 2005-04-13T06:38:18Z
From: Rich FitzJohn
Subject: how to separate a string
In-Reply-To: <20050413062352.52175.qmail@web30701.mail.mud.yahoo.com>

To get the first character from a string, use substr(s, 1, 1)

To split strings at a period, use strsplit(s, "\\.") (the period must
be quoted, as "." matches anything in a regular expression).

To get the index for "." in a string, see "?regexpr, but you will not
need to do that if you use strsplit().

Cheers,
Rich

On 4/13/05, Cuichang Zhao <cuiczhao at yahoo.com> wrote:
> hello, 
> i wonder how is string represent in R. if i have a string s= "hello", how
> can i refer to first character in the string s? 
> also if i have s1 = "hello.1", s2 = "ok.1",  how can i separate the s1 into
> "hello" "1" and s2 into "ok" and "1"? I have tried to use the substring
> function, but i don't where i can get the index for "." in the string?
>  
> Thank you so much
>  
> C-Ming
> April 12, 2005
> 
> 		
> ---------------------------------
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> 

-- 
Rich FitzJohn
rich.fitzjohn <at> gmail.com   |    http://homepages.paradise.net.nz/richa183
                      You are in a maze of twisty little functions, all alike