- [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
[C#] Hướng dẫn đảo nội dung bài viết trong lập trình winform
Xin chào các bạn, bài viết hôm nay mình sẻ tiếp tục hướng dẫn các bạn các đảo nội dung bài viết trong lập trình C#, winform.
[C#] How to Rotate Text in csharp Winform
VD: mình có đoạn văn như sau
- Tin 1 : “mua ban sim so dep,cho thue sim so dep,lien he 0989 999 999“
- Tin 2: “cho thue sim so dep, mua ban sim so dep,lien he 0989 999 999“
- Tin 3: “lien he 0989 999 999,mua ban sim so dep, cho thue sim so dep“
- Tin 4 : “cho thue sim so dep,lien he 0989 999 999, mua ban sim so dep“
Ở đoạn trên, các bạn thấy các dữ liệu trong đoạn được đảo nhau bằng cách dấu phẩy (,)
Thuật toán ở đây chúng ta muốn đảo đơn giản là:
VD: abc => kết quả đảo
acb, bca, cab, abc, cba, bac.
Từ abc có 3 ký tự: số kết quả đảo được chính là 3! = 6 (3 giai thừa)
Giao diện demo ứng dụng đảo đoạn văn bản C#, winform:
Các bạn có thể ứng dụng này để làm content spin.
Class Algorithms.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpinEditorApp.Helpers
{
class Algorithms
{
private int elementLevel = -1;
private int numberOfElements;
private int[] permutationValue = new int[0];
private char[] inputSet;
public char[] InputSet
{
get { return inputSet; }
set { inputSet = value; }
}
private int permutationCount = 0;
public int PermutationCount
{
get { return permutationCount; }
set { permutationCount = value; }
}
public char[] MakeCharArray(string InputString)
{
char[] charString = InputString.ToCharArray();
Array.Resize(ref permutationValue, charString.Length);
numberOfElements = charString.Length;
return charString;
}
public void Recursion(int k)
{
elementLevel++;
permutationValue.SetValue(elementLevel, k);
if (elementLevel == numberOfElements)
{
OutputPermutation(permutationValue);
}
else
{
for (int i = 0; i < numberOfElements; i++)
{
if (permutationValue[i] == 0)
{
Recursion(i);
}
}
}
elementLevel--;
permutationValue.SetValue(0, k);
}
public List<string> list = new List<string>();
private void OutputPermutation(int[] value)
{
var list_temp = new List<string>();
foreach (int i in value)
{
var _char = inputSet.GetValue(i - 1).ToString();
list_temp.Add(_char);
Console.Write(inputSet.GetValue(i - 1));
}
list.Add(string.Join(",", list_temp));
Console.WriteLine();
PermutationCount++;
}
}
}
Full source code Rotate Text c#:
using SpinEditorApp.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RotateSentence
{
public partial class Form1 : Form
{
public readonly char SYMBOL = ',';
public Form1()
{
InitializeComponent();
}
private async void btn_rotate_Click(object sender, EventArgs e)
{
var content = txt_input.Text.Trim();
var dataRotate = await RotateTextAsync(content);
lbl_result.Text = $"Kết quả đảo nội dung: {dataRotate.Count} kết quả đảo được.";
dataGridView1.DataSource = dataRotate;
}
public Task<List<Article>> RotateTextAsync(string content)
{
var task = Task.Run(() =>
{
var articles = new List<Article>();
var line = content.Split(SYMBOL);
var char_temp = "";
for (int i = 0; i < line.Length; i++)
{
char_temp += i;
}
Algorithms permAlgorithm = new Algorithms();
permAlgorithm.InputSet = permAlgorithm.MakeCharArray(char_temp);
permAlgorithm.Recursion(0);
var data = permAlgorithm.list;
foreach (var index in data)
{
List<string> list_data_temp = new List<string>();
var arr = index.Split(',');
foreach (var pos in arr)
{
var pos_int = Convert.ToInt32(pos);
list_data_temp.Add(line[pos_int]);
}
var rotateText = string.Join(",", list_data_temp);
var article = new Article();
article.id = articles.Count() + 1;
article.content = rotateText;
articles.Add(article);
}
return articles;
});
return task;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://laptrinhvb.net");
}
}
public class Article
{
public int id { get; set; }
public string content { get; set; }
}
}
Thanks for watching!