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

Discuss the spreadsheet application

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

Postby gutee » Mon Jan 21, 2019 5:12 am

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

Postby gutee » Mon Jan 21, 2019 5:27 am

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

Postby gutee » Mon Jan 21, 2019 5:53 am

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

Postby gutee » Mon Jan 21, 2019 8:19 am

Cell_Str2 = Replace(Cell_Str,CHR$(10),","), this code works.
OpenOffice.org.3.3.0
gutee
 
Posts: 19
Joined: Wed Jan 09, 2019 9:12 am

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

Postby Lupp » Mon Jan 21, 2019 3:40 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

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

Postby Villeroy » Mon Jan 21, 2019 4:13 pm

=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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27239
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby Lupp » Mon Jan 21, 2019 4:17 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

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

Postby Villeroy » Mon Jan 21, 2019 4:22 pm

Code: Select all   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27239
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Calc

Who is online

Users browsing this forum: Zizi64 and 19 guests