Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove single space between text

Tags:

python

r

This is the input given "S H A N N O N B R A D L E Y" (single space between each letter but 2 space between SHANNON and BRADLEY) I want output to be in this format (given below)

SHANNON BRADLEY

Any way to do this in R or Python

like image 892
Utsav Bhargava Avatar asked May 19 '15 07:05

Utsav Bhargava


People also ask

How to delete spaces between words in Excel?

Select one or several columns with the data to delete spaces between words. Press Ctrl + H to get the " Find and Replace " dialog box. Press the Space bar twice in the Find What field and once in Replace With Click on the " Replace all " button, and then press Ok to close Excel confirmation dialog.

How do I find and replace double spaces in text?

In Microsoft Word, press CTRL + H to access the find-and-replace tool. In Adobe InDesign, press CTRL + F while any text frame is active to open the Find/Replace box. This article explains how to find double spaces and replace them with single spaces using a variety of programs.

What are the different types of text spacing in HTML?

1 Text Indentation 2 Letter Spacing. The letter-spacing property is used to specify the space between the characters in a text. 3 Line Height 4 Word Spacing. The word-spacing property is used to specify the space between the words in a text. 5 White Space. The white-space property specifies how white-space inside an element is handled.

How do I get rid of double-spaced characters in word?

In the program in which you're working, press the Search and Replace hotkey or its equivalent. Search for two spaces and set it to replace with a single space. Run this procedure several times, until your program advises you that no more occurrences of a double-spaced character set were found.


1 Answers

try this in R

text <- c("S H A N N O N  B R A D L E Y")

gsub(" (?! )" , text , replacement = "" , perl = T)

this is another simpler one

gsub("\\b " , text , replacement = "" , perl = T)
like image 165
Nader Hisham Avatar answered Oct 22 '22 06:10

Nader Hisham