You've been given a workable solution already, but here's a one-liner:
> x <- c('sta_+1+0_field2ndtry_$01.cfg' ,
> 'sta_+B+0_field2ndtry_$01.cfg' , 'sta_+1+0_field2ndtry_$01.cfg' ,
> 'sta_+9+0_field2ndtry_$01.cfg')
> sapply(1:length(x), function(i)gsub("\\+(.*)\\+.", paste("\\+\\
You are too good :)
Thanks a lot have a nice weekend
B.R
Alex
From: jim holtman
Cc: "R-help@r-project.org"
Sent: Friday, December 2, 2011 1:51 PM
Subject: Re: [R] find and replace string
try this:
> x <- c('sta_+1+0_fi
If the length of the fists part is constant (the "sta_+1+" part) the
you can use substr()
On 2 December 2011 13:30, Alaios wrote:
>
Dear all,
> I would like to search in a string for the second occurrence of a symbol and
> replace the symbol after it
>
> For example my strings look like
>
>
try this:
> x <- c('sta_+1+0_field2ndtry_$01.cfg'
+ , 'sta_+1+0_field2ndtry_$01.cfg'
+ , 'sta_+1-0_field2ndtry_$01.cfg'
+ , 'sta_+1+0_field2ndtry_$01.cfg'
+ )
> # find matching fields
> values <- grep("[^+]*\\+[^+]*\\+0", x, value = TRUE)
> # split into two piec
Dear all,
I would like to search in a string for the second occurrence of a symbol and
replace the symbol after it
For example my strings look like
sta_+1+0_field2ndtry_$01.cfg
I want to find the digit that comes after the second +, in that case is zero
and then over a loop create the strin
5 matches
Mail list logo