TextArea adding a blank line when reading from text file.

I’m reading from a section of a text file and placing the text into a TextArea. Everything is fine, except for it’s adding a blank line right above the text. I’m not sure why this is happening. There is no blank line in the text file itself in the section that is being read.

Probably something simple I’m overlooking.

[code]Dim t as TextInputStream
t = TextInputStream.Open(file)
dim s as String = t.ReadAll

Dim rg as New RegEx
rg.SearchPattern="##PACKAGING_NOTES_MARKER##(.*)##DEPLOYMENT_NOTES_MARKER##"
rg.Options.Greedy = False
rg.Options.DotMatchAll = True
Dim myMatch as RegExMatch = rg.search(s)
if myMatch <> nil then
EDIT.PACKAGING_TEXTAREA.Text=myMatch.SubExpressionString( 1 )
t.Close
else
t.Close
end[/code]

  1. make sure when you open the file you us DEFINE ENCODING when you read the data or set the equivalent property on the text input stream
  2. you may want to use
Dim t as TextInputStream
t = TextInputStream.Open(file)
dim s as String = ReplaceLineEndings(t.ReadAll, EndOfLine)

to make sure that whatever line endings in the file are converted into a consistent style for your code

[quote=472968:@Norman Palardy]1) make sure when you open the file you us DEFINE ENCODING when you read the data or set the equivalent property on the text input stream
2) you may want to use

Dim t as TextInputStream
t = TextInputStream.Open(file)
dim s as String = ReplaceLineEndings(t.ReadAll, EndOfLine)

to make sure that whatever line endings in the file are converted into a consistent style for your code[/quote]

That has no effect.

without the text file you’re reading its hard to know what else might be causing this
do you have any initial value set for this text area ?
any other code that adds data to it anywhere else ?

have you put a breakpoint on the line that reads the data and then stepped and looked at the contents of S after you read the data ?

The text file is being created by the same XOJO app. Nothing special.

Here’s what that section looks like directly from the text file itself.

##PACKAGING_NOTES_MARKER##
Test
##DEPLOYMENT_NOTES_MARKER##

So, when I grab the contents between these markers (which is the word test) it creates a blank line in the TextArea right above the word “test”.

note that ##PACKAGING_NOTES_MARKER## ends with a NEWLINE which is retained as part of subexpression 1 and thats probably your newline

How do I compensate for that?

Dim t as TextInputStream
t = TextInputStream.Open(file)
dim s as String = t.ReadAll

Dim rg as New RegEx
rg.SearchPattern="##PACKAGING_NOTES_MARKER##(.*)##DEPLOYMENT_NOTES_MARKER##"
rg.Options.Greedy = False
rg.Options.DotMatchAll = True
Dim myMatch as RegExMatch = rg.search(s)
if myMatch <> nil then
  EDIT.PACKAGING_TEXTAREA.Text = trim(myMatch.SubExpressionString( 1 ))
  t.Close
else
  t.Close
end

Thanks, Norman!

FWIW I figured this our just using the debugger and looking inside the different variables that were in use