zoukankan      html  css  js  c++  java
  • 根据标点符号分行,StringBuilder的使用;将字符串的每个字符颠倒输出,Reverse的使用

    一:根据标点符号分行,上图,代码很简单

    二:代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Lines
    {
        public partial class Frm_Main : Form
        {
            public Frm_Main()
            {
                InitializeComponent();
            }
    
            private void btn_true_Click(object sender, EventArgs e)
            {
                StringBuilder P_stringbuilder = //创建字符串处理对象
                    new StringBuilder(txt_string.Text);
                for (int i = 0; i < P_stringbuilder.Length; i++)//开始循环
                    if (P_stringbuilder[i] == ',')//判断是否出现(,)号
                        P_stringbuilder.Insert(++i,//向字符串内添加换行符
                            Environment.NewLine);
                txt_Lines.Text = //得到分行后的字符串
                    P_stringbuilder.ToString();
                bool P_bl = "abc" == "abc";
                MessageBox.Show(P_bl.ToString());
            }
        }
    }

     三:将字符串的每个字符颠倒输出,上图:

    四:相关代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ReverseStr
    {
        public partial class Frm_Main : Form
        {
            public Frm_Main()
            {
                InitializeComponent();
            }
    
            private void txt_input_TextChanged(object sender, EventArgs e)
            {
                char[] P_chr=txt_input.Text.ToCharArray();//从字符串中得到字节数组
                Array.Reverse(P_chr, 0, txt_input.Text.Length);//反转字节数组(对象字符数组,起始位置,反转长度)
                txt_output.Text = //将字节数组转换为字符串并输出
                    new StringBuilder().Append(P_chr).ToString();
            }
        }
    }
  • 相关阅读:
    AutoCAD利用VBA设置线型和添加用户自定义线性
    AutoVBA利用for循环创建同心圆弧
    AutoVBA利用Hacth对象填充图元对象
    AutoVBA利用AddArc方法创建Arc对象
    2011年6月5日星期天
    AutoVBA控件的tabindex和tabstop属性及with语句
    AutoVBA在绘图空间创建直线对象
    AutoVBA利用toolbar创建自己的工具栏
    AutoVBA调用AddCricle方法绘制圆
    AutoCAD利用VBA宏绘制多重平行线
  • 原文地址:https://www.cnblogs.com/hongmaju/p/3738261.html
Copyright © 2011-2022 走看看