Page 1 of 1

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

Posted: Mon Jan 21, 2019 5:12 am
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"," ")

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

Posted: Mon Jan 21, 2019 5:27 am
by gutee
PS. I just need to get the final_cell_str as :
str1,str2,str3
---------------
|str1
|str2
|str3
---------------

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

Posted: Mon Jan 21, 2019 5:53 am
by gutee
this is also similar for the question : how to judge the cell has multi-lines and to put them into array.
Thanks.

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

Posted: Mon Jan 21, 2019 8:19 am
by gutee
Cell_Str2 = Replace(Cell_Str,CHR$(10),","), this code works.

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

Posted: Mon Jan 21, 2019 3:40 pm
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.

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

Posted: Mon Jan 21, 2019 4:13 pm
by Villeroy
=SUBSTITUTE(A1;CHAR(10);" ")

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

Posted: Mon Jan 21, 2019 4:17 pm
by Lupp
Yes. Of course.
But the questioner posted user code, and I was wondering if it actually was Basic or something else.

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

Posted: Mon Jan 21, 2019 4:22 pm
by Villeroy

Code: Select all

mid sInput, instr(sInput, Chr(10)), 1, " "
or some decent macro langauge with batteries included.