- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
[VB.NET] Hướng dẫn chuyển đổi code HTML to BB code
Bài viết hôm nay, mình xin hướng dẫn các bạn cách chuyển đổi code từ code HTML to BBcode. Trong bài viết trước, mình đã có làm một bài hướng dẫn về cách đăng tin tự động lên diễn đàn Xenforo. Để đăng lên được các diễn đàn Forum, các bạn cần phải convert code từ HTML sang BBcode, thì post nó mới hiểu.
Bảng tag element của HTML và BBcode.
Dưới đây, là hàm convert HTML to BBcode, các bạn chỉ cần sử dụng Regular Expression đề xử lý. Các bạn có thể tìm hiểu bài Regular trong lập trình Csharp để tham khảo.
Public Function FormatHtmlIntoBBCode(desc As String) As String
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<br(.*?)>", "[br]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<br(.*?)>", "[br]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<ul[^>]*>", "[ulist]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "", "[/ulist]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<ol[^>]*>", "[olist]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "", "[/olist]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<li>", "[*]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</li>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<b>", "[b]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</b>", "[/b]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<strong>", "[strong]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</strong>", "[/strong]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<u>", "[u]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</u>", "[/u]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<i>", "[i]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</i>", "[/i]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<em>", "[em]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</em>", "[/em]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<sup>", "[sup]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</sup>", "[/sup]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<sub>", "[sub]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</sub>", "[/sub]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<hr[^>]*>", "[hr]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<strike>", "[strike]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</strike>", "[/strike]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<h1>", "[h1]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</h1>", "[/h1]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<h2>", "[h2]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</h2>", "[/h2]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<h3>", "[h3]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, "</h3>", "[/h3]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
'desc = System.Text.RegularExpressions.Regex.Replace(desc, "[br]", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim match As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(desc, "<img[ss]*?src=""([ss]*?)""[ss]*?>", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
If match.Count > 0 Then
desc = System.Text.RegularExpressions.Regex.Replace(desc, match(0).ToString(), "[img]" + match(0).Groups(1).Value + "[/img]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
End If
desc = System.Text.RegularExpressions.Regex.Replace(desc, "<a href="" ",="" "[url=", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, " <="" a="">", "[/url]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
'desc = System.Text.RegularExpressions.Regex.Replace(desc, "<span style="" color:",="" "[color=", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
'desc = System.Text.RegularExpressions.Regex.Replace(desc, " <="" span="">", "[/color]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = System.Text.RegularExpressions.Regex.Replace(desc, """>", "]", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
desc = desc.Replace("[br]", "")
desc = desc.Replace("<p>", "")
desc = desc.Replace("</p>", "")
Return desc
End Function
CHÚC CÁC BẠN THÀNH CÔNG!