欢迎使用CSDN-markdown编辑器

来源:互联网 发布:易凯软件 编辑:程序博客网 时间:2024/06/05 04:44

OLED软件再优化

最近笔者在玩OLED时发现官方的取模软件生成的序列无法直接在程序中使用,还需要不停的加逗号和前缀,所以我决定做一个优化版的桌面应用程序,使得序列能够直接粘贴到你程序的数组中使用。

以16*16汉字字模为例
这里写图片描述
这是直接从取模软件中取出的序列,如果直接粘贴到程序中,我们需要删除部分东西,还需要加上逗号以及大括号等,非常麻烦(昨天由于重复操作,我的键盘按钮就不幸坏掉一个)。
看效果图
这里写图片描述
序列经过我对字符串的处理,直接生成了代码中能用的数组,用户可以直接粘贴到程序中直接使用,而省去了繁琐的修改。

谈谈代码

其实这是一个很简单的桌面程序,只需要对C#字符串处理有了解的同学都能实现,笔者采用的算法就是找到每一个H的位置,然后对每个位置进行相应的裁剪和修改。

代码块

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ChangeText
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[] H_number;
int i = 0;
int num = 0;
string strCreate;
private void btnCreate_Click(object sender, EventArgs e)
{
string str = tbSrcText.Text;
char[] temp = tbSrcText.Text.ToCharArray();
H_number = new int[100];
foreach (char c in temp)
{
if (c == ‘H’)
{
H_number[i] = num;
i++;
}
num++;
}
for (int j = 0; j < i + 1; j++)
{
if(j == 0)
{
strCreate = strCreate + “{“;
}
if (j == i/2)
{
strCreate = strCreate.Substring(0, strCreate.Length - 1);
strCreate = strCreate +”}” + “,” +”\r\n”;
strCreate = strCreate + “{“;
}

            if (H_number[j] == 0)                break;             strCreate = strCreate + "0x" + str.Substring(H_number[j] - 2, 3) + ",";             str = tbSrcText.Text;        }        strCreate = strCreate.Substring(0, strCreate.Length - 1);        strCreate = strCreate + "}";        tbCreateText.Text = strCreate;         //tbCreateText.Text = tbSrcText.Text;    }    private void btnPaste_Click(object sender, EventArgs e)    {        if (tbCreateText.Text == "")        {            MessageBox.Show("没有文本粘贴");        }        else        {            Clipboard.SetDataObject(tbCreateText.Text);            MessageBox.Show("文本已经粘贴");        }    }}

}

PS:第一次写博客,还希望大家多多指教。有关算法希望那个大家可以互相交流

0 0