replace commas of sql with newlines

[expired user #5298]'s profile image [expired user #5298] posted 13 years ago in General Permalink
I tried to use the editor ctrl+r with regular expressions to replace commas with new lines.
i tried \n and \\n and it did not work.
how can i do it?
kalvaro's profile image kalvaro posted 13 years ago Permalink
I can confirm it's not working as expected. If you use \n in a replacement expression you n as replacement.
ansgar's profile image ansgar posted 13 years ago Permalink
The replacement string is never a regular expression, and things like \n \t and maybe more should be usable with or without having the regular expression option activated. Found this issue report for Lazarus, which probably helps me with some code change for SynEdit.
ansgar's profile image ansgar posted 13 years ago Permalink
Not so easy as that might seem. Thought I just string-replace these \n with a real #13#10 right before replacement is processed. Now, TSynMemo.SearchReplace does this when I replace commas with newlines:
original:

1,2,3,4


replaced:

1


2,3,4



Looks like a bug in SynEdit.
ansgar's profile image ansgar posted 13 years ago Permalink
Looks like SynEdit always processes only the number of lines which is found in the original text:

1,
2,
3,
4,
5,
6,
7


is replaced with:

1

2

3

4,
5,
6,
7

ansgar's profile image ansgar posted 13 years ago Permalink
Hm, looks as if even Lazarus still has the above mentioned issue with the number of processed lines. Think we need a different, working approach here. Fixing SynEdit does not seem realistic to me.
Code modification/commit from ansgar.becker, 13 years ago, revision 6.0.0.3928
Add support for \t and \n for replacement in search+replace dialog. Accepting a multi line bug in SynEdit, which forces the user to search backwards when using \n in replacement. See http://www.heidisql.com/forum.php?t=8977
ansgar's profile image ansgar posted 13 years ago Permalink
Done in r3928, supporting \n and \t now. Accepting the above bug in SynEdit, which is the same as in other applications, e.g. PSPad. The user has to use backward search to overcome that bug.
[expired user #5298]'s profile image [expired user #5298] posted 13 years ago Permalink
That's cool :-)
I am just asking myself, if i make replace all with a regular expresssion, that the program should automatically replace everything backwards?
Maybe a suggestion.
ansgar's profile image ansgar posted 13 years ago Permalink
Again, please note that \n and \t are not part of the regular expression feature.

Your suggestion is to automatically check the "backwards" radio button when the replacement string contains \n and "replace all" is clicked. Well, why not.
Code modification/commit from ansgar.becker, 13 years ago, revision 6.0.0.3929
Implicitly activate backwards search when replacement string contains \n, to overcome the multi line bug described in previous commit. Suggestion from michaelgang, see http://www.heidisql.com/forum.php?t=8977
ansgar's profile image ansgar posted 13 years ago Permalink
Done in r3929
[expired user #5298]'s profile image [expired user #5298] posted 13 years ago Permalink
Vielen Dank !!!
ansgar's profile image ansgar posted 13 years ago Permalink
Danke dir für die gute Idee - hatte bereits graue Haare wegen des SynEdit Bugs und dann so eine einfache Idee, super.
[expired user #5298]'s profile image [expired user #5298] posted 13 years ago Permalink
smile

Please login to leave a reply, or register at first.