Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does StreamWriter drop leading tabs? 1

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,
Here's what's happening: I, the Program, read a "truncated" XML file which I need to format and write back N times.
Formatting code:
Code:
' Add 4 Tab chars in front of every line 1st:
lsBlock = lsBlock.Replace(vbCrLf, vbCrLf & Replicate(Chr(9), 4))

' The starting tag <CheckDetail> - move it 1 tab to the right
lsBlock = lsBlock.Replace(Replicate(Chr(9), 4) & "<CheckDetail>", Replicate(Chr(9), 3) & "<CheckDetail>")
' The ending tag </CheckDetail> - move it 1 tab to the left:
lsBlock = lsBlock.Replace(Replicate(Chr(9), 4) & "</CheckDetail>", Replicate(Chr(9), 3) & "</CheckDetail>")

Dim loStreamWriter As New StreamWriter(tcFileOut, True)

'Add compound section's starting tag
loStreamWriter.Write(Replicate(Chr(9), 2) & "<CheckDetails>" & vbCrLf)
Then the For-Next cycle to write the whole block these N times - nothing interesting, so I skip it here, and I stop at the moment after the Stream is filled out.
So far, so good: note that, at the break point, the lcBlock in the Locals does have these leading Tabs.
20200402_StreamWriterDropsLeadingTabs_i4cxuj.jpg


But when I open the output file...
20200402_StreamWriterDropsLeadingTabs_Output_efh2dx.jpg

This bloody <CheckDetail> tag is written w/o those leading Tabs!

Hence the question in subject.
OR
Do I do something wrong?
Please advise.

TIA!

Regards,

Ilya
 
Before we proceed ... i'm assuming that Replicate is essentially an alias for strdup

The only way I can almost replicate your problem is if the first character(s) in lsBlock at this point in your code

' Add 4 Tab chars in front of every line 1st:
lsBlock = lsBlock.Replace(vbCrLf, vbCrLf & Replicate(Chr(9), 4))

are not vbCrLf
 
Bleen! (T's in Russian [soapbox] , you don't wanna kno...)
How stupid this old senile fool me could be! [blush]
The opening tag <CheckDetail> starts from pos. 1, and of course the line

Code:
lsBlock = lsBlock.Replace(Replicate(Chr(9), 4) & "<CheckDetail>", Replicate(Chr(9), 3) & "<CheckDetail>")

does nothing!

Thank you, colleague! [thanks2] U R Z Man! [bow]

Problem resolved, case is being closed.

Regards,

Ilya
 
Блеен - I know it as a very tasty 'pancake' [wavey]


---- Andy

There is a great need for a sarcasm font.
 
Actually, "pancake" in Russian is "блин" (I write "bleen" in order for Anglophones to pronounce it properly), but it's also euphemism for the Russian cursing word as expression of utmost disappointment.
Just FYI.

Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top