- [C#] Viết ứng dụng Auto Fill list Textbox from clipboard Winform
- [TOOL] Chia sẻ phần mềm thay đổi thông tin cấu hình máy tính
- [C#] Hướng dẫn Export dữ liệu ra file Microsoft Word Template
- [C#] Chia sẻ source code tool kiểm tra domain website
- [C#] Hướng dẫn tạo file PDF sử dụng thư viện QuestPDF
- [C#] Hướng dẫn tạo ứng dụng dock windows giống Taskbar
- [C#] Chia sẻ source code sử dụng Object Listview trên Winform
- [VB.NET] Chia sẻ source code quản lý thu chi mô hình 3 lớp Winform
- [DATABASE] Xóa lịch sử danh sách đăng nhập tài khoản trên SMSS Sqlserver Management Studio
- [C#] Sử dụng FolderBrowserDialog Vista trên Winform
- [DEVEXPRESS] Chia sẻ tool Winform UI Templates Early Access Preview (EAP)
- [C#] Chia sẻ source code Spin Content (Trộn nội dung văn bản theo từ đồng nghĩa) trên Winform
- [VB.NET] Chia sẻ source code lịch âm dương và hẹn lịch nhắc việc
- [C#] Hướng dẫn đọc thông số thiết bị Thiết bị kiểm tra Pin (HIOKI BATTERY HiTESTER BT3562)
- [VB.NET] Hướng dẫn giải captcha sử dụng dịch vụ AZCaptcha API trên winform
- [C#] Hướng dẫn chứng thực đăng nhập ứng dụng bằng vân tay (Finger Print) trên máy tính
- [C#] Color Thief cách xuất màu sắc thiết kế từ hình ảnh
- [C#] Cách tạo bản quyền và cho phép dùng thử ứng dụng Winform
- [C#] Hướng dẫn sử dụng trình duyệt web Chrome convert HTML sang tập tin file PDF
- [C#] Kết nôi điện thoại Android, IOS với App Winform via Bluetooth
[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!