Removing special chars in strings?

classic Classic list List threaded Threaded
6 messages Options
.
Reply | Threaded
Open this post in threaded view
|

Removing special chars in strings?

.
Hi all,

How can I replace those "\" in the str?

Thanks in advance.

func <- function(str) {
  print(gsub("\\","",str))
}
func("bla\ble\bli")

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Removing special chars in strings?

Mikhail Titov-2
I usually use something like [\\]

Mikhail

On 08/31/2011 08:32 PM, . . wrote:

> Hi all,
>
> How can I replace those "\" in the str?
>
> Thanks in advance.
>
> func <- function(str) {
>   print(gsub("\\","",str))
> }
> func("bla\ble\bli")
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Removing special chars in strings?

William Dunlap
In reply to this post by .
There are no backslash characters in the string "bla\ble\bli".
"\b" is used to indicate a backspace character, just
as "\n" is used to indicate a newline character.

You can get rid of the backslash characters with
  > gsub("\b","","bla\ble\bli")
  [1] "blaleli"
or change them to b's with
  > gsub("\b","b","bla\ble\bli")
  [1] "blablebli"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of . .
> Sent: Wednesday, August 31, 2011 6:33 PM
> To: [hidden email]
> Subject: [R] Removing special chars in strings?
>
> Hi all,
>
> How can I replace those "\" in the str?
>
> Thanks in advance.
>
> func <- function(str) {
>   print(gsub("\\","",str))
> }
> func("bla\ble\bli")
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Removing special chars in strings?

William Dunlap
Typo below:

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of William Dunlap
> Sent: Wednesday, August 31, 2011 6:47 PM
> To: . .; [hidden email]
> Subject: Re: [R] Removing special chars in strings?
>
> There are no backslash characters in the string "bla\ble\bli".
> "\b" is used to indicate a backspace character, just
> as "\n" is used to indicate a newline character.
>

> You can get rid of the XbackslashX characters with
                          backspace

>   > gsub("\b","","bla\ble\bli")
>   [1] "blaleli"
> or change them to b's with
>   > gsub("\b","b","bla\ble\bli")
>   [1] "blablebli"
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> > -----Original Message-----
> > From: [hidden email] [mailto:[hidden email]] On Behalf Of . .
> > Sent: Wednesday, August 31, 2011 6:33 PM
> > To: [hidden email]
> > Subject: [R] Removing special chars in strings?
> >
> > Hi all,
> >
> > How can I replace those "\" in the str?
> >
> > Thanks in advance.
> >
> > func <- function(str) {
> >   print(gsub("\\","",str))
> > }
> > func("bla\ble\bli")
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
.
Reply | Threaded
Open this post in threaded view
|

Re: Removing special chars in strings?

.
In reply to this post by William Dunlap
I got it!

Where did I find the table relating the code and the respective meaning?

I want to replace ".

Thanks

On Wed, Aug 31, 2011 at 10:47 PM, William Dunlap <[hidden email]> wrote:

> There are no backslash characters in the string "bla\ble\bli".
> "\b" is used to indicate a backspace character, just
> as "\n" is used to indicate a newline character.
>
> You can get rid of the backslash characters with
>  > gsub("\b","","bla\ble\bli")
>  [1] "blaleli"
> or change them to b's with
>  > gsub("\b","b","bla\ble\bli")
>  [1] "blablebli"
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of . .
>> Sent: Wednesday, August 31, 2011 6:33 PM
>> To: [hidden email]
>> Subject: [R] Removing special chars in strings?
>>
>> Hi all,
>>
>> How can I replace those "\" in the str?
>>
>> Thanks in advance.
>>
>> func <- function(str) {
>>   print(gsub("\\","",str))
>> }
>> func("bla\ble\bli")
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Removing special chars in strings?

William Dunlap
> -----Original Message-----
> From: . . [mailto:[hidden email]]
> Sent: Wednesday, August 31, 2011 6:59 PM
> To: William Dunlap
> Cc: [hidden email]
> Subject: Re: [R] Removing special chars in strings?
>
> I got it!
>
> Where did I find the table relating the code and the respective meaning?

Did you start with help("character")?  Aside from the \a they are
the traditional C ones (e.g., Kernighan and Richie, 1978, p 181).

 \a   alert (bell)
 \b   backspace
 \t   tab
 \n   newline
 \v   vertical space
 \f   formfeed
 \r   carriage return (without newline)
 \'   single quote
 \"   double quote

print() shows the backslashed version (except for \', which is not
required) and cat() causes the user interface to display their
"meaning".  Not all user interfaces support all of them.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


>
> I want to replace ".
>
> Thanks
>
> On Wed, Aug 31, 2011 at 10:47 PM, William Dunlap <[hidden email]> wrote:
> > There are no backslash characters in the string "bla\ble\bli".
> > "\b" is used to indicate a backspace character, just
> > as "\n" is used to indicate a newline character.
> >
> > You can get rid of the backslash characters with
> >  > gsub("\b","","bla\ble\bli")
> >  [1] "blaleli"
> > or change them to b's with
> >  > gsub("\b","b","bla\ble\bli")
> >  [1] "blablebli"
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >> -----Original Message-----
> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of . .
> >> Sent: Wednesday, August 31, 2011 6:33 PM
> >> To: [hidden email]
> >> Subject: [R] Removing special chars in strings?
> >>
> >> Hi all,
> >>
> >> How can I replace those "\" in the str?
> >>
> >> Thanks in advance.
> >>
> >> func <- function(str) {
> >>   print(gsub("\\","",str))
> >> }
> >> func("bla\ble\bli")
> >>
> >> ______________________________________________
> >> [hidden email] mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.