C# 数据16进制转10进制,richtextbox中查找字符串

>>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";
>         }
>     } }
> 
> ``
  • 1
    点赞
  • 6
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 点我我会动 设计师:白松林 返回首页

打赏作者

山东小磁针

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值