有几个函数的用法?/在线等待......有分送的

XXSingle 2003-04-23 12:14:01
怎样从一串字符串全部转成大写?
怎样截取字符串中的空格(左,中,右)?
...全文
33 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CinnXu 2003-04-23
  • 打赏
  • 举报
回复
System.string.Trim() 是去除空格
System.string.ToUpper()转换大写
wordinchina 2003-04-23
  • 打赏
  • 举报
回复
分别实现截取字符串中的空格(左,中,右)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace stringcom
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Button button4;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.button4 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(80, 32);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 1;
this.label1.Text = "input";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 2;
this.label2.Text = "upper";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(80, 80);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 3;
this.textBox2.Text = "textBox2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 80);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "do";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 120);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 23);
this.label3.TabIndex = 5;
this.label3.Text = "left";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(80, 120);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 6;
this.textBox3.Text = "textBox3";
//
// button2
//
this.button2.Location = new System.Drawing.Point(192, 120);
this.button2.Name = "button2";
this.button2.TabIndex = 7;
this.button2.Text = "do";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 160);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 23);
this.label4.TabIndex = 8;
this.label4.Text = "mid";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(80, 160);
this.textBox4.Name = "textBox4";
this.textBox4.TabIndex = 9;
this.textBox4.Text = "textBox4";
//
// button3
//
this.button3.Location = new System.Drawing.Point(192, 160);
this.button3.Name = "button3";
this.button3.TabIndex = 10;
this.button3.Text = "do";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 200);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(56, 23);
this.label5.TabIndex = 11;
this.label5.Text = "right";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(80, 200);
this.textBox5.Name = "textBox5";
this.textBox5.TabIndex = 12;
this.textBox5.Text = "textBox5";
//
// button4
//
this.button4.Location = new System.Drawing.Point(192, 200);
this.button4.Name = "button4";
this.button4.TabIndex = 13;
this.button4.Text = "do";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button4,
this.textBox5,
this.label5,
this.button3,
this.textBox4,
this.label4,
this.button2,
this.textBox3,
this.label3,
this.button1,
this.textBox2,
this.label2,
this.label1,
this.textBox1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
string tempstr=textBox1.Text;
textBox2.Text=tempstr.ToUpper();
}

private void button2_Click(object sender, System.EventArgs e)
{
string tempstr=textBox1.Text;
textBox3.Text=tempstr.TrimStart(' ');
}

private void button4_Click(object sender, System.EventArgs e)
{
string tempstr=textBox1.Text;
textBox5.Text=tempstr.TrimEnd(' ');
}

private void button3_Click(object sender, System.EventArgs e)
{
string tempstr=textBox1.Text;
string strtmp=null;
for(int i=0;i<tempstr.Length;i++)
{
if(tempstr[i]!=' ')
{
strtmp=strtmp+tempstr[i];
// MessageBox.Show("ok");
}
}
textBox4.Text=strtmp;
}
}
}
eyesluo 2003-04-23
  • 打赏
  • 举报
回复
upper,trim

查msdn吧
XXSingle 2003-04-23
  • 打赏
  • 举报
回复
多谢--------------
Knight94 2003-04-23
  • 打赏
  • 举报
回复
去除空格:Trim(' ');

110,552

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧