Skip to content

Commit 9d61e95

Browse files
github-actions[bot]KB Bot
and
KB Bot
authored
Added new kb article editor-parsing-comments-list-radeditor-content (#527)
Co-authored-by: KB Bot <[email protected]>
1 parent 90d2d47 commit 9d61e95

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Parsing Comments in a List from RadEditor Content
3+
description: Learn how to parse out all the comments in a list from the content of RadEditor using VB.NET or C# in a button click event.
4+
type: how-to
5+
page_title: Parsing Comments in a List from RadEditor Content
6+
slug: editor-parsing-comments-list-radeditor-content
7+
tags: radeditor, comments, list, parse, vb.net, c#
8+
res_type: kb
9+
---
10+
11+
## Environment
12+
| Product | RadEditor for ASP.NET AJAX |
13+
| ------- | ------------------------- |
14+
| Version | all |
15+
16+
## Description
17+
I want to parse out all the comments in a list from the content of RadEditor using VB.NET or C# in a button click event.
18+
19+
## Solution
20+
To parse out all the comments in a list from the content of RadEditor in a button click event, follow these steps:
21+
22+
1. Get the content from the RadEditor control.
23+
2. Use a regular expression to find `<span>` tags with the `reComment` class and extract the comment attribute.
24+
3. Create a list to hold the comments.
25+
4. Match all instances and extract the comments.
26+
5. Output the comments to a label or any other control.
27+
28+
Here's an example solution using VB.NET:
29+
30+
````C#
31+
protected void btnExtractComments_Click(object sender, EventArgs e)
32+
{
33+
// Get the content from RadEditor
34+
string editorContent = theEditor.Content;
35+
36+
// Regular expression to find span tags with the reComment class and extract the comment attribute
37+
Regex regex = new Regex("<span[^>]*class=\"[^\"]*reComment[^\"]*\"[^>]*comment=\"(.*?)\"[^>]*>", RegexOptions.IgnoreCase);
38+
39+
// Create a list to hold the comments
40+
List<string> commentsList = new List<string>();
41+
42+
// Match all instances and extract comments
43+
foreach (Match match in regex.Matches(editorContent))
44+
{
45+
if (match.Success)
46+
{
47+
// Extract the comment attribute
48+
string comment = match.Groups[1].Value;
49+
commentsList.Add(comment);
50+
}
51+
}
52+
53+
// Output the comments to a label or any other control
54+
lblComments.Text = string.Join("<br/>", commentsList);
55+
}
56+
````
57+
````VB
58+
Protected Sub btnExtractComments_Click(sender As Object, e As EventArgs)
59+
' Get the content from RadEditor
60+
Dim editorContent As String = theEditor.Content
61+
62+
' Regular expression to find span tags with the reComment class and extract the comment attribute
63+
Dim regex As New Regex("<span[^>]*class=""[^""]*reComment[^""]*""[^>]*comment=""(.*?)""[^>]*>", RegexOptions.IgnoreCase)
64+
65+
' Create a list to hold the comments
66+
Dim commentsList As New List(Of String)
67+
68+
' Match all instances and extract comments
69+
For Each match As Match In regex.Matches(editorContent)
70+
If match.Success Then
71+
' Extract the comment attribute
72+
Dim comment As String = match.Groups(1).Value
73+
commentsList.Add(comment)
74+
End If
75+
Next
76+
77+
' Output the comments to a label or any other control
78+
lblComments.Text = String.Join("<br/>", commentsList)
79+
End Sub
80+
````
81+
82+
You can modify this code per your requirements and use it to parse out the comments from the RadEditor content in a button-click event.
83+

0 commit comments

Comments
 (0)