[Solved] split cell at first space

Discuss the spreadsheet application
Post Reply
User avatar
mike.ritter
Posts: 4
Joined: Wed May 28, 2008 5:01 am
Location: usa

[Solved] split cell at first space

Post by mike.ritter »

How does one split a cell at the first space in Calc? Example: [filename my file description] to [filename] [my file description]. Merge/Split does not work. Data -> Text to Columns does not work. Perhaps I am looking for a formula that looks for the first instance of the [:space:] character using regular expressions as in a find and replace, but I do not know the proper function or syntax. :?:
Last edited by mike.ritter on Wed May 28, 2008 7:34 am, edited 1 time in total.
Computers aren't just for geeks, but they sure make us look good.
Windows XP SP2 : OOo 2.4.0
6'2" 160lbs.
Peanut Butter and Jelly
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: split cell at first space

Post by Villeroy »

"Does not work" could mean anything. Cell merging and splitting is about appearance rather than content. The text-to-columns should do the job.
Text in A1 and B assumed as first empty column:
B1: =SEARCH("[:space:]+";A1) One space at least. Due to a bug, regexes with a trailing named class [:somename:] fail. I use to add a quantifier such as +
C1: =MID(A1;B1;1)=" " Just a test if the found space is a plain " " (ascii-code 32). If not, it would explaing the failure of text-to-columns
D1: =LEFT(A1;B1-1) Left part before the space.
E1: =MID(A1;B1+1;LEN(A1)) Rest behind the space
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
mike.ritter
Posts: 4
Joined: Wed May 28, 2008 5:01 am
Location: usa

Re: split cell at first space

Post by mike.ritter »

Villeroy, the code returned a null value (#VALUE) beginning in each cell.
Computers aren't just for geeks, but they sure make us look good.
Windows XP SP2 : OOo 2.4.0
6'2" 160lbs.
Peanut Butter and Jelly
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: split cell at first space

Post by Villeroy »

Menu:Tools>Options...Calc>Calculation:[X]Enable regular expressions in formulas (this is off by default for all xls since Excel has no regexes)
If it still returns #VALUE then there is no space. Test: Type a space somewhere in the middle of the value.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
mike.ritter
Posts: 4
Joined: Wed May 28, 2008 5:01 am
Location: usa

Re: split cell at first space

Post by mike.ritter »

Excellent! To wrap this up, for those who find the solution, if you want to use the information later copy the contents of D1 and E1 then "Paste Special" -> deselect all but "Text" into F1 and G1 respectively.
Computers aren't just for geeks, but they sure make us look good.
Windows XP SP2 : OOo 2.4.0
6'2" 160lbs.
Peanut Butter and Jelly
Post Reply