Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:58:27+00:00 2026-06-14T13:58:27+00:00

I have a vector of strings: x<-c(abc.dat, xyz.dat) First I would like to replace

  • 0

I have a vector of strings:

x<-c("abc.dat", "xyz.dat")

First I would like to replace the period character “.” within each string with another character i.e. “-” minus sign and then append again with “-” minus sign character at the start of each string and finally concatenate all the string within the vector to form a final single string and assigning it to some object like str_final so.

>str_final (enter)
-abc-dat -xyz-dat

Any help will be really appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:58:28+00:00Added an answer on June 14, 2026 at 1:58 pm

    Look at ?gsub and ?paste

    > paste0("-", gsub("\\.", "-", c("abc.dat", "xyz.dat")))
    [1] "-abc-dat" "-xyz-dat"
    

    Notice that I escaped the dot with 2 backslashes. Alternatively, you can use fixed=TRUE like this gsub(".", "-", c("abc.dat", "xyz.dat"), fixed=TRUE)


    If you want a single string, maybe you want to make use of the collapse argument to paste

    > paste(paste0("-", gsub("\\.", "-", c("abc.dat", "xyz.dat"))), collapse=" ")
    [1] "-abc-dat -xyz-dat"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::vector<std::string> which would contain numbers and characters (single char). I would
I would like to pass a vector of strings from C++ to MATLAB. I
I have vector of strings and want to create a fixed with string out
A have a vector of strings in c++: vector<string> myVect = {A, A, A,
I have a vector of strings: std::vector<std::string> fName which holds a list of file
I have a large collection of unique strings (about 500k). Each string is associated
I have a Vector < String >. Now i want to store those Strings
I'd like to split a vector of character strings (people's names) into two columns
I would like to concatenate strings stored in a vector. For example if I
I have a vector filled with strings of the following format: <year1><year2><id1><id2> the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.