[Solved] Replace '\n' in a multi line in a Cell

Discuss the spreadsheet application
Post Reply
gutee
Posts: 19
Joined: Wed Jan 09, 2019 9:12 am

[Solved] Replace '\n' in a multi line in a Cell

Post by gutee »

I have a cell with multi lines, I use the oCell.getString() and there are '\n' in the result.
when I try to replace '\n' to ' ', it failed with following code, it seems the tool did not found \n in the multi line cell.
final_cell_str = Replace(oCell.getString(),"\n"," ")
Last edited by robleyd on Mon Jan 21, 2019 8:51 am, edited 1 time in total.
Reason: Tagged [Solved] [robleyd, Moderator]
OpenOffice.org.3.3.0
gutee
Posts: 19
Joined: Wed Jan 09, 2019 9:12 am

Re: Replace '\n' in a multi line in a Cell

Post by gutee »

PS. I just need to get the final_cell_str as :
str1,str2,str3
---------------
|str1
|str2
|str3
---------------
OpenOffice.org.3.3.0
gutee
Posts: 19
Joined: Wed Jan 09, 2019 9:12 am

Re: Replace '\n' in a multi line in a Cell

Post by gutee »

this is also similar for the question : how to judge the cell has multi-lines and to put them into array.
Thanks.
OpenOffice.org.3.3.0
gutee
Posts: 19
Joined: Wed Jan 09, 2019 9:12 am

Re: Replace '\n' in a multi line in a Cell

Post by gutee »

Cell_Str2 = Replace(Cell_Str,CHR$(10),","), this code works.
OpenOffice.org.3.3.0
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Replace '\n' in a multi line in a Cell

Post by Lupp »

As far as I know there never was a built-in function 'Replace' in OOo or AOO Basic. There are some additional Basic-functions coded themselves based on built-in functions and delivered with the software in the Basic container 'OpenOffice Macros'. The library 'Tools' there has a module 'Strings' providing a function 'ReplaceString' where the second and the third parameter are in reverse order as compared with the usage of 'Replace' in the above posted example.

I would like to know what function 'Replace' you actually accessed.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Replace '\n' in a multi line in a Cell

Post by Villeroy »

=SUBSTITUTE(A1;CHAR(10);" ")
Last edited by Villeroy on Mon Jan 21, 2019 4:22 pm, edited 2 times in total.
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
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Replace '\n' in a multi line in a Cell

Post by Lupp »

Yes. Of course.
But the questioner posted user code, and I was wondering if it actually was Basic or something else.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Replace '\n' in a multi line in a Cell

Post by Villeroy »

Code: Select all

mid sInput, instr(sInput, Chr(10)), 1, " "
or some decent macro langauge with batteries included.
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
Post Reply