[R] Re: how to separate a string

From: Rich FitzJohn <rich.fitzjohn_at_gmail.com>
Date: Wed 13 Apr 2005 - 16:38:18 EST

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@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@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

______________________________________________
R-help@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
Received on Wed Apr 13 16:47:31 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:07 EST