EOL: String related exceptions [message #1736838] |
Sat, 02 July 2016 15:40 |
Alireza Rouhi Messages: 148 Registered: December 2015 |
Senior Member |
|
|
Hi,
I have a string comment s with the following value:
/*
* comment line 1
* comment line 2
* comment line 3
*/
I want to remove the '/*' and '*' from this string. When I use the following statement to remove '*' from the s string:
s.replace("*","").println();
I get the following exception error:
Internal error: java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
Finally, I would like to display the string on the console view without any '/*' and '*'. Of course, it seems that copying the string (character by character, except '/*' and '*') can be a solution here. However, I cannot implement this approach as well! Since the string copy loop as following,
var t: String;
var i: Integer = 0;
while (i < s.length())
{
if (s.charAt(i) <> "*" and s.charAt(i) <> "/") // it's always 'true'
{
t.println();
t = t + s.charAt(i);
}
i = i + 1;
}
t.println();
is not working as I expect!
Is there any trick to solve this problem?
Best regards,
Alireza
[Updated on: Mon, 04 July 2016 07:28] Report message to a moderator
|
|
|
Re: EOL: String related exceptions [message #1737026 is a reply to message #1736838] |
Tue, 05 July 2016 07:57 |
|
Hi Alireza,
> I get the following exception error:
s..replaceAll("\\*","") would work.
> is not working as I expect!
Off the top of my head charAt() returns chars instead of strings. (charAt(...) + "") = "*" should work.
Cheers,
Dimitris
|
|
|
|
Powered by
FUDForum. Page generated in 0.03261 seconds