all groups > visual studio .net ide > october 2006 >
You're in the

visual studio .net ide

group:

Search and Replace with newlines


Search and Replace with newlines Steve Shaw
10/26/2006 4:10:02 PM
visual studio .net ide:
This apparent bug has cropped up a few times in the past, but I finally
decided to pursue it this time. I picked up a query from SQL Profiler and
pasted it into a new text file in Visual Studio 2005. I wanted to economize
on screen space a bit, so I wanted to collapse the select list into a single
line. It looked like this originally:

SELECT j1.Id 't36',
j1.ACCDomain 't37',
j1.ACCSelectLevel 't38',
j1.AccessControlList 't41',
j1.GPersonPolTREvent_Restricted 't19',
j1.ACCModifyLevel 't44',
j1.NACLockInformation 't47',
j1.GPersonPolTREvent_Locked 't20',
j1.GPersonPolTREvent_TemplateProperties 't23',
j1.GPersonPolTREvent_ESSigningPerson1SignType 't25',
j1.GPersonPolTREvent_ESSigningPerson2SignType 't27',
j1.CreUser 't54',
j1.CreTime 't58',
j0.Id 't5',
j0.GPersonPolLegalDoc_AppearanceCourtMandatory 't6',
j0.GPPLDAppearanceCourt_Id 't281',
j0.GPPLDAppearanceCourt_Id 't292',
j0.GPPLDAppearanceCourt_Time 't293',
j0.GPPLDAppearanceCourt_TimeOffset 't296',
j0.GPPLDAppearanceCourt_TimeOffsetName 't299',
j0.GPersonPolLegalDoc_IdNumber 't11',

I highlighted the select list portion of the query and attempted to do a
regular expression search and replace. I wanted to replace "\n\t" with " "
to collapse newlines and the subsequent tab characters with a single space.
The result I got was:

SELECT j1.Id 't36', j1.ACCDomain 't37', j1.ACCSelectLevel 't38',
j1.AccessControlList 't41',
j1.GPersonPolTREvent_Restricted 't19',
j1.ACCModifyLevel 't44',
j1.NACLockInformation 't47',
j1.GPersonPolTREvent_Locked 't20',
j1.GPersonPolTREvent_TemplateProperties 't23',
j1.GPersonPolTREvent_ESSigningPerson1SignType 't25',
j1.GPersonPolTREvent_ESSigningPerson2SignType 't27',
j1.CreUser 't54',
1.CreTime 't58',
.Id 't5',
j0.GPersonPolLegalDoc_AppearanceCourtMandatory 't6',
j0.GPPLDAppearanceCourt_Id 't281',
j0.GPPLDAppearanceCourt_Id 't292',
j0.GPPLDAppearanceCourt_Time 't293',
j0.GPPLDAppearanceCourt_TimeOffset 't296',
j0.GPPLDAppearanceCourt_TimeOffsetName 't299',
j0.GPersonPolLegalDoc_IdNumber 't11',

The first couple of lines collapsed correctly, but then there are a bunch of
lines that are not touched at all. About 2/3 of the way through a couple of
lines are bizarrely mutilated, with missing characters (but no newlines
removed). Even stranger, if I hit undo and then re-run the search and
replace, I get different results. It occurred to me that the problem might
have something to do with inconsistent line endings, so I tried saving the
file and using the "Advanced save options" to set the line endings to both
"Windows (CR LF)" and "Unix (LF)". Neither option made any difference.

My question is whether I am doing something wrong here? Is this a known
issue and if so is there is any workaround? If not, is this a bug I should
be reporting through some channel? Does it even happen to anyone else? I
haven't been able to find reports of similar issues elsewhere on the web.
Re: Search and Replace with newlines martin.douglas NO[at]SPAM gmail.com
10/27/2006 10:18:42 AM
The lines that were not moved are because of spaces. Rather than there
being a tab character preceeding each line, it has say 4 spaces. The
mangled entries look like those I have experienced in the past when
"hidden" characters are present. Generally this is caused do to a
copy/paste from another application, such as Query Analyzer, where one
way or another a character with ASCII below 32 was introduced. One way
to verify this is to paste the same code into Notepad2.exe for example
and turn on hidden character display.

Best regards - MD
Re: Search and Replace with newlines Steve Shaw
10/27/2006 11:35:02 AM
No, I considered that possibility, and when I was testing it, I checked the
text using "Edit | Advanced | View White Space". There was nothing but
proper tabs at the beginning of each line. The text pasted into the original
message is exactly the text I was working with, and it has tabs at the
beginning of each line (unless third party newsreaders mess it up somehow -
if I pick it up with Outlook Express it is fine, I know that). Did you get a
chance to try and reproduce this behaviour? If you take my sample text and
do the same search and replace, does it behave strangely? Interestingly
enough, seems to work fine with Visual Studio 2003.

[quoted text, click to view]
AddThis Social Bookmark Button