如何将字符串的第一个和拉伸字显示在文本框中 [英] how to display first and las word of string into textbox

查看:53
本文介绍了如何将字符串的第一个和拉伸字显示在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

公司表格如下



Compid Compname

1面膜



我有一个文本框如下

Company_username textbox1



我有gridview如下

在gridview我显示从公司表记录并显示到gridview



Compid Compname

select 1 Mask



当我点击gridview中的select时,我想要显示同名的第一个字母M和最后一个字母K,以便在textbox1中显示。



在textbox1中我想要输出如下



Company_username Mk



我怎样才能在asp.net中使用c#。

Company table as follows

Compid Compname
1 Mask

I have one textbox as follows
Company_username textbox1

I have gridview as follows
In gridview i show record from company table and display into gridview

Compid Compname
select 1 Mask

I want when i click the select in gridview i want to show companame first letter M and last letter K to be displayed in the textbox1.

In the textbox1 i want output as follows

Company_username Mk

from that how can i do in asp.net using c#.

推荐答案

假设您能够从 GridView 中获取字符串,您只需使用 String.Su bstring 方法,例如

Assuming you are able to get the string from the GridView, you have just to use String.Substring method, e.g.
public static string Collapse(string str)
{
  if (str.Length <= 2) return str;
  return str.Substring(0,1) + str.Substring(str.Length-1);
}
public static void Main()
{
  string [] a = { "fox", "go", "b", "", "12344560"};

  foreach (string s in a)
      Console.WriteLine("{0}, {1}", s, Collapse(s));
}


这篇关于如何将字符串的第一个和拉伸字显示在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆