Iterating CrLf lines in Text

Hi,

I’m new to Xojo and have some beginners trouble converting my experienced .NET brain to Xojo’s …

I need to parse a Text (not coming from a file, otherwise TextInputStream would fit) which contains multiple lines separated by CrLf or Lf (both versions can occur). In .NET I would do this:

For Each strLine As String In strCrLfText.Split(vbLf)
   strLine = strLine.Trim({" ", vbCr, vbLf})
   If strLine = "" Then Continue

   'do something

Next

Maybe I’ve overlooked something in the manual, but the mix of classic and new Framework in there is confusing. As I’m building something great (…) in iOS I’m using the new Framework here.

What have you tried? I would think something like this would work:

[code]Const vbLF = &u0A
Const vbCR = &u0D
For Each strLine As Text In strCrLfText.Split(vbLF)
strLine = strLine.Replace(vbCR, “”)
strLine = strLine.Replace(vbLF, “”)
strLine = strLine.Trim

’ do something
Next[/code]

Or a replacement function for ReplaceLineEndings:

Protected Function ReplaceLineEndings(src As Text, other As Text) As Text
  const kCR as Text = &u0D
  const kLF as Text = &u0A
  const kCRLF as Text = &u0D + &u0A
  
  //
  // Normalize the line endings first
  //
  src = src.ReplaceAll( kCRLF, kLF )
  src = src.ReplaceAll( kCR, kLF )
  
  //
  // Now replace them
  //
  src = src.ReplaceAll( kLF, other )
  
  return src
  
End Function

This comes directly from the M_Text module available on my web site:

http://www.mactechnologies.com/index.php?page=downloads#m_text

Thx.

What confused me was:

  1. I made a mistake within the loop, resulting in Xojo also pointing at the For and Next lines of the loop (…).
  2. I did also, once, used multiple characters in the Split, like Split(vbCrLf), which is possible in .NET but Xojo apparently only accepts one character for the Split. NB: vbCrLf is a constant I made.

Xojo accept any string for the split