Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

regexp "\n" in treplace

Hello,
I have to move from a string field all the "\n".
I have tried the EREPLACE and the CHANGE fonctions in tMap but the half run: the "\n" is reached but not replaced and the replace string is added after the "\n".
Then I have tried the tReplace, but I have the same problem.
0683p000009MCab.jpg
Labels (2)
8 Replies
_AnonymousUser
Specialist III
Specialist III

Hello
If you want to replace a character you can use this function : yourtable.yourfield.replaceAll("\\\n", " ");
With that all "\n" will be replace by " "
the \\ is needed to make correctly this operation. I hope that will works
_AnonymousUser
Specialist III
Specialist III

Hello
If you want to replace a character you can use this function : yourtable.yourfield.replaceAll("\\\n", " ");
With that all "\n" will be replace by " "
I did that with Tmap but I don't know if it works with others components
the \\ is needed to make correctly this operation. I hope that will works
amaumont
Contributor III
Contributor III

In fact several syntaxes seems to work:
        String string = "test1\ntest2";
System.out.println("original:" + string);;
System.out.println("1:" + "test1\ntest2".replaceAll("\n", " "));;
System.out.println("2:" + "test1\ntest2".replaceAll("\\n", " "));;
System.out.println("3:" + "test1\ntest2".replaceAll("\\\n", " "));;
System.out.println("4:" + "test1\ntest2".replaceAll("\\\\n", " "));;

give result:
original:test1
test2
1:test1 test2
2:test1 test2
3:test1 test2
4:test1
test2
Anonymous
Not applicable
Author

I'm sorry but it doesn't work!
See datas please:
In the second image, you can see the input data. || is the \n.
In the third image, you can see the tMap function I use
In the first image the result.

You see that The job has found the \n but hasn't replace it. The job has added the space after the \n.
What is the problem in my job?
Thanks for reply.
0683p000009MCag.jpg 0683p000009MCal.jpg 0683p000009MCBo.jpg
amaumont
Contributor III
Contributor III

Ok, I found your problem, this a DOS file with \r\n (not only \n):
        String string = "test1\r\n\r\ntest2";
System.out.println("original:" + string);;
System.out.println("1:" + string.replaceAll("\n", " "));
System.out.println("2:" + string.replaceAll("\\n", " "));
System.out.println("3:" + string.replaceAll("\\\n", " "));
System.out.println("4:" + string.replaceAll("\\\\n", " "));
System.out.println("5:" + string.replaceAll("\r\n", " "));
System.out.println("6:" + string.replaceAll("(\r\n)+", " "));

give:
original:test1
test2
1:test1

test2
2:test1

test2
3:test1

test2
4:test1
test2
5:test1 test2
5:test1 test2

So the best pattern to use is:
(\r\n)+
Anonymous
Not applicable
Author

Thanks very much.
It's running well.
Anonymous
Not applicable
Author

Hi,
Ok, I found your problem, this a DOS file with \r\n (not only \n):
        String string = "test1\r\n\r\ntest2";
System.out.println("original:" + string);;
System.out.println("1:" + string.replaceAll("\n", " "));
System.out.println("2:" + string.replaceAll("\\n", " "));
System.out.println("3:" + string.replaceAll("\\\n", " "));
System.out.println("4:" + string.replaceAll("\\\\n", " "));
System.out.println("5:" + string.replaceAll("\r\n", " "));
System.out.println("6:" + string.replaceAll("(\r\n)+", " "));

give:
original:test1
test2
1:test1

test2
2:test1

test2
3:test1

test2
4:test1
test2
5:test1 test2
5:test1 test2

So the best pattern to use is:
(\r\n)+


Referring to no 5. How to remove space in between the test1 and test2? Instead of "test1 test2". I want it to be "test1test2". I have similar problem like this.
Thanks in advance!
_AnonymousUser
Specialist III
Specialist III

Hi,
use "" and not " " in replaceAll : string.replaceAll("(\r\n)+", ""))
best regards
Jeremie