ListBox: String internal format of copied Rows

When I copy data (more than one Row) from a ListBox, what is the format of the string data placed in the Clipboard Class ?

Specifically, I want to know the EndOfLine value: the value of the lines separator.

Tab separated. EndOfLine is platform dependent, as usual.

It does not seems to me that it is true.

When I copy more than one Row and try to paste it (them), all I get is one Row with many, many (new) Columns.

When I used ReplaceLineEndings, the things comes back to normal.

[code]Dim Clip As New Clipboard
Dim LineCnt As Integer // Number of lines in the Clipboard
Dim TheData As String // The Clipboard contents
Dim OneRow As String // One line of Text, will be added in a new Row
Dim LoopIdx As Integer // Loop indice

If Clip.TextAvailable Then
// Get the text from the Clipboard with the correct line endings
TheData = ReplaceLineEndings(Clip.Text, EndOfLine) // *

// How many available Rows in the Clipboard ?
LineCnt = CountFields(TheData, EndOfLine)

For LoopIdx = 1 To LineCnt
  // Get the Clipboard contents
  OneRow = NthField(TheData, EndOfLine, LoopIdx)
  
  // AddRow for this line
  LB.AddRow Split(OneRow, Chr(9)) // Add one Row
Next

End If [/code]

Remove the line marked * and you cannot get the number of Rows you previously copied.

I have no code to copy Rows. Xojo do it for me.

Xojo uses chr(13) often, so it is probably that, but you can get it by inspection in the debugger.

I have checked. It is chr(13), as usual with Mac. But indeed, EndOfLine does not work. Whatever. Using chr(13) to split the data does the job fine. Why make it more complicated ?

[code] dim c as new clipboard
Dim s As String
Dim TheData as String= c.Text
c.Close

Lb.addrow “”

Dim Lines(-1) as string
Lines = split(TheData, chr(13))

For LoopIdx as integer = 0 To Lines.Ubound
// AddRow for this line
LB.AddRow “”
LB.Cell(LB.LastIndex,-1) =Lines(LoopIdx) // Add one Row
Next[/code]

I always do a ReplaceLineEndings before splitting with endofline. Sometimes texts do have mixed line endings.

The funny thing is that here, I looked at the string, and the only character at the end of the line is indeed chr(13) which is normally EndOfLine.Macintosh.

But this is an excellent suggestion, it works perfectly :

[code] dim c as new clipboard
Dim s As String
Dim TheData as String= c.Text
c.Close

Lb.addrow “”

Dim Lines(-1) as string
Lines = split(ReplaceLineEndings(TheData,EndOfLine), EndOfLine)

For LoopIdx as integer = 0 To Lines.Ubound
// AddRow for this line
LB.AddRow “”
LB.Cell(LB.LastIndex,-1) =Lines(LoopIdx) // Add one Row
Next[/code]

Thank you Christian.

IIRC, Carbon uses chr(13) while Cocoa uses Chr(10) - EndOfLine.Unix.

Oh. I have been too long in that business of programming the Mac. Did not realize it had changed.

The interesting thing is that when copying a line ending, Mac OS X still uses chr(13). I verified that with SimpleText. It may yet be another story under Windows. Hopefully ReplaceLineEndings will take care of it as well.

Good catch ! I do not think at that !

How ?
For me, it was a series of fields separated with a Tab and ended by a line ending. No way to know these line endings values. *

Windows:
Works the same as OS X. I always check on WIndows after falling in a trap and founding a solution.

Prior the use of ReplaceLineEndings, I noticed that AddRow add all Columns found in the Clipboard (total number of Columns: if you copu 3 Rows that have 4 COlumns, you will get around 12 Columns - or more if the EndOfLine Character is counted as an empty Column).

  • But these gaves me a clue: that is why I goes to ReplaceLineEndings.

Before all of that, I was believing the same as Michel (Tab + EndOfLine).

[quote=129161:@Emile Schwarz]How ?
For me, it was a series of fields separated with a Tab and ended by a line ending. No way to know these line endings values. *
[/quote]

I just copied a line ending from SimpleText, and then processed the clipboard string like so :

For i as integer = 1 to len(s) TextArea1.Text = TextArea1.Text+str( asc(mid(s,i,1)) ) )+" " next

Just a guess, but I bet this code was just never updated.

Looks like it. But it also could be not to break existing applications.

I tried to force feed chr(10) to the clipboard, it becomes chr(13) when retrieved.

[quote=129161:@Emile Schwarz] @Michel Bujardet I verified that with SimpleText.

How ?[/quote]
Michel:

the How was related with SimpleText. Note that I do not think at that too. Where my my brain when I was in need ?

Greg: do you recall when and why ReplaceLineEndings was added into what became Xojo ?

ReplaceLineEndings has existed for a VERY VERY VERY long time.
Long before the switch to Xojo.
I just checked my 2007r4 and its there and I know it was there before then.

The BEST way to handle it when you’re not certain what the line endings are is to use ReplaceLineEndings and make SURE what they are.

The oldest reference I found (google) dates from 2004 and that reference were let me think ReplaceLineEndings is older than that.

Thanks Norman.