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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值