Property Strings
Strings
Gets or sets a list of strings to parse.
[Browsable(false)]
public virtual IStringList Strings { get; set; }
Property Value
Examples
Here is how to use a Strings in the C# code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using Alternet.Syntax;
public partial class Form1 : Form
{
private const int tokComment = 11;
private IList<string> comments = new List<string>();
private IList<string> multilineComments = new List<string>();
private Parser parser = new Parser();
private void ParseComment()
{
Point pos = parser.TokenPosition;
StringBuilder sb = new StringBuilder();
while (!parser.Eof && parser.Token == tokComment)
{
sb.AppendLine(parser.TokenString);
parser.NextToken();
}
if (parser.CurrentPosition.Y > pos.Y)
multilineComments.Add(sb.ToString());
else
comments.Add(sb.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
parser.Strings = new StringList();
comments.Clear();
parser.Strings.LoadFile("text.txt");
parser.Reset();
while (!parser.Eof)
{
if (parser.Token == tokComment)
ParseComment();
parser.NextToken();
}
}
}
Here is how to use a Strings in the Visual Basic code:
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Text
Imports Alternet.Syntax
Partial Public Class Form1
Inherits Form
Private Const tokComment As Integer = 11
Private comments As IList(Of String) = New List(Of String)()
Private multilineComments As IList(Of String) = New List(Of String)()
Private parser As Parser = New Parser()
Private Sub ParseComment()
Dim pos As Point = parser.TokenPosition
Dim sb As StringBuilder = New StringBuilder()
While Not parser.Eof AndAlso parser.Token = tokComment
sb.AppendLine(parser.TokenString)
parser.NextToken()
End While
If parser.CurrentPosition.Y > pos.Y Then
multilineComments.Add(sb.ToString())
Else
comments.Add(sb.ToString())
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
parser.Strings = New StringList()
comments.Clear()
parser.Strings.LoadFile("text.txt")
parser.Reset()
While Not parser.Eof
If parser.Token = tokComment Then ParseComment()
parser.NextToken()
End While
End Sub
End Class
Remarks
Each item in the list represents a text line parsed by the Parser component.
This collection is altered as the user types the text in the SyntaxEdit control, to which this parser is linked.