>>using System;
>>using System.Collections.Generic;
>>using System.ComponentModel;
>>using System.Drawing;
>>using System.Linq;
>>using System.Text;
>>using System.Threading.Tasks;
>>using System.Windows.Forms;
> namespace textStringDemo {
> public partial class Form1 : Form
> {
> public Form1()
> {
> InitializeComponent();
> }
> /// <summary>
> /// 数据解析,将16进制字符串解析
> /// </summary>
> /// <param name="sender"></param>
> /// <param name="e"></param>
> private void button1_Click(object sender, EventArgs e)
> {
> try
> {
> string textStrInPut = "AB CD EF 01";
> //去空格
> //textStrInPut = textStrInPut.Replace(" ","");
> //截取字符串
> //textStrInPut = textStrInPut.Remove(0,2);
> //截取字符串
> //SubString(m, n) ; m为需要截取的字符串索引位置, n为 截取长度
>
> ///定义字符串
> string txt4H10 = "";//4H10D
> string txt6H10 = "";//6H10D
> string txt8H10 = "";//8H10D
> string txtWG26 = "";//WG26
> string txtWG34 = "";//WG34
>
> ///字符串赋值
> txt4H10 = Convert.ToInt64(textStrInPut.Replace(" ", "").Remove(0, 4), 16).ToString();
> txt6H10 = Convert.ToInt64(textStrInPut.Replace(" ", "").Remove(0, 2), 16).ToString();
> txt8H10 = Convert.ToInt64(textStrInPut.Replace(" ", "").Remove(0, 0), 16).ToString();
> txtWG26 = Convert.ToInt64(textStrInPut.Replace(" ", "").Substring(2, 2), 16).ToString() + "," +
> Convert.ToInt64(textStrInPut.Replace(" ", "").Remove(0, 4),
> 16).ToString();
> txtWG34 = Convert.ToInt64(textStrInPut.Replace(" ", "").Substring(0, 4), 16).ToString() + "," +
> Convert.ToInt64(textStrInPut.Replace(" ", "").Remove(0, 4),
> 16).ToString();
>
> ///解析显示
> labz4H10DWG26.Text = txt4H10 + " " + txtWG26;
> labz4H10DWG34.Text = txt4H10 + " " + txtWG34;
> labz6H10DWG26.Text = txt6H10 + " " + txtWG26;
> labz6H10DWG34.Text = txt6H10 + " " + txtWG34;
> labz8H10DWG26.Text = txt8H10 + " " + txtWG26;
> labz8H10DWG34.Text = txt8H10 + " " + txtWG34;
>
> int textFindStrNum = 0;
> //查找richtextbox中是否存在该字符串
> ///参数: 1 ===>目标字符串,即需要查找字符串
> ///参数: 2 ===>
> ///参数: 3 ===>决定从什么地方开始
> textFindStrNum = rhtbxText.Find("bcf", 0, RichTextBoxFinds.None);
> if (textFindStrNum > 3)
> MessageBox.Show("该字符串存在!!!========>" + textFindStrNum);
> else
> MessageBox.Show("该字符串不存在");
> }
> catch (Exception err)
> {
> MessageBox.Show(err.Message);
> }
>
> finally
> {
>
> }
> }
>
> private void Form1_Load(object sender, EventArgs e)
> {
> rhtbxText.Text = "abcdefg\nhijklmn\nopq\nrst\nuvw\nxyz\nbcf";
> }
> } }
>
> ``
C# 数据16进制转10进制,richtextbox中查找字符串
最新推荐文章于 2025-02-21 00:15:00 发布