substring

public String substring(int beginIndex,
int endIndex)
返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,一直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex

示例:

 "hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"
参数:
beginIndex - 开始处的索引(包括)。
endIndex - 结束处的索引(不包括)。
返回:
指定的子字符串。
抛出:
IndexOutOfBoundsException - 如果 beginIndex 为负,或 endIndex 大于此 String 对象的长度,或 beginIndex 大于 endIndex

在本例中,我们将使用 substring() 从字符串中提取一些字符:

<script type="text/javascript">

var str="Hello world!"
document.write(str.substring(3,7)) </script>

输出:

lo w

2.show与ShowDialog

A.WinForm中窗体显示  
显示窗体可以有以下2种方法: 
Form.ShowDialog方法 (窗体显示为模式窗体) 
Form.Show方法 (窗体显示为无模式窗体)  2者具体区别如下: 
1.在调用Form.Show方法后,Show方法后面的代码会立即执行 
2.在调用Form.ShowDialog方法后,直到关闭对话框后,才执行此方法后面的代码 
3.当窗体显示为模式窗体时,单击“关闭”按钮会隐藏窗体,并将DialogResult属性设置为DialogResult.Cancel 
与无模式窗体不同,当用户单击对话框的关闭窗体按钮或设置DialogResult属性的值时,不调用窗体的Close方法 
实际上是把窗体的Visible属性赋值为false,隐藏窗体了 
这样隐藏的窗体是可以重新显示,而不用创建该对话框的新实例 
因为未关闭窗体,所以在应用程序不再需要该窗体时,请调用该窗体的Dispose方法  怎么判断一个窗体是模式窗体呢? 
利用Form.Modal属性,如果该窗体是模式显示,则为true,否则为false 
根据通过Show和ShowDialog而显示出来的窗体的Modal属性分别对应false和true 
特别注意: 
由于在窗体创建之前是无法得知显示方式的,所以在窗体构造函数中,Modal属性总是对应false,所以我们只能在Load事件中或者之后利用Modal属性值  怎么确定窗体间的所有者关系? 
Form类的Owner属性:窗体的所有者 
当一个窗体归另一窗体所有时,它便随着所有者窗体最小化和关闭。 
例如,如果Form2归窗体Form1所有,则关闭或最小化Form1时,Form2也会关闭或最小化。  例如在窗体Form1中 
Form2 f2 = new Form2 ( ); 
f2.ShowDialog ( this ); 
//或者 
f2.Show ( this ); 
//或者 
f2.Owner = this; 
f2.ShowDialog( );  这样f2的所有者就是Form1  B.WinForm窗体传值 
了解了窗体的显示相关知识,接着总结一下窗体的传值方法:  1.通过构造函数 
特点:传值是单向的(不可以互相传值),实现简单 
实现代码如下: 
在窗体Form2中 
int value1; 
string value2;  public Form2 ( int value1 , string value2 ) 

InitializeComponent ( );  this.value1 = value1; 
this.value2 = value2; 
}  在窗体Form1中这样调用 
new Form2 ( 111 , "222" ).Show ( ); //这样就把111,"222",这2个值传送给了Form2  2.通过静态变量 
特点:传值是双向的,实现简单 
实现代码如下: 
在一个app类中定义一个静态成员value 
public class app 

public static string value; 
}  在窗体Form1中这样调用 
app.value = "f2"; //给静态成员赋值 
new Form2 ( ).Show ( ); //显示Form2  在窗体Form2中 
this.Text = app.value; //取回app.value的值 
app.value = "Form2"; //给app.value赋值,以便其他窗体调用  3.通过窗体的公有属性值 
特点:实现简单 
实现代码如下:  在窗体Form2中定义一个公有属性Form2Value,获取和设置textBox1的文本值 
public string Form2Value 

get 

return this.textBox1.Text; 

set 

this.textBox1.Text = value; 

}  在窗体Form1中这样调用 
Form2 f2 = new Form2 ( ); 
f2.Form2Value = "Ok"; //给Form2的textBox1赋值Ok 
f2.ShowDialog ( );  4.通过窗体的公有属性值和Owner属性 
特点:实现简单,灵活 
实现代码如下: 
在窗体Form1中 
public int Form1Value = 1;  Form2 f2 = new Form2 ( ); 
f2.ShowDialog ( this ); //把Form1作为Form2的所有者传递给Form2  在窗体Form2中 
//Form2的所有者是Form1 
Form1 f1 = ( Form1 ) this.Owner; 
//取到Form1的值是1 
MessageBox.Show ( f1.Form1Value .ToString ( ) ); 
//给Form1的Form1Value赋值222 
f1.Form1Value = 222;  5.通过窗体的公有属性值和Application.OpenForms属性 
说明:Application.OpenForms属性:获取属于应用程序的打开窗体的集合。(此属性在 .NET Framework2.0版中) 
实现代码如下: 
在窗体Form1中 
public int Form1Value = 1;  Form2 f2 = new Form2 ( ); 
f2.Show ( );  在窗体Form2中 
string formName = "Form1"; 
Form fr = Application.OpenForms [ formName ];  if ( fr != null ) 

Form1 f1 = ( Form1 ) fr; 
//取到Form1的值是1 
MessageBox.Show ( f1.Form1Value.ToString ( ) ); 
//给Form1的Form1Value赋值222 
f1.Form1Value = 222; 
}  6.通过事件 
实现代码如下: 
在窗体Form2中定义公有属性Form2Value,获取和设置textBox1的文本值 
并且还定义一个accept事件 
public string Form2Value 

get 

return this.textBox1.Text; 

set 

this.textBox1.Text = value; 

}  public event EventHandler accept;  private void button1_Click ( object sender , EventArgs e ) 

if ( accept != null ) 

accept ( this , EventArgs.Empty ); //当窗体触发事件,传递自身引用 

}  在窗体Form1中 
Form2 f2 = new Form2 ( ); 
f2.accept += new EventHandler ( f2_accept ); 
f2.Show ( );  void f2_accept ( object sender , EventArgs e ) 

//事件的接收者通过一个简单的类型转换得到Form2的引用 
Form2 f2 = (Form2) sender; 
//接收到Form2的textBox1.Text 
this.textBox1.Text = f2.Form2Value; 
}

show与ShowDialog substring的更多相关文章

  1. 从字符串总分离文件路径、命名、扩展名,Substring(),LastIndexOf()的使用;替换某一类字符串,Replace()的用法

    一:从字符串总分离文件路径.命名.扩展名,上图 二:代码 using System; using System.Collections.Generic; using System.ComponentM ...

  2. C#利用substring按指定长度分割字符串

    这几天学习分析声音的波形数据,接收到的是十六进制的数据,需要将数据转换成十进制再绘图,这个过程涉及到字符串的分割,正好可以促进自己对C#相关知识的学习.说到分割字符串,我首先想到的是Split,但根据 ...

  3. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  4. 最长回文子串-LeetCode 5 Longest Palindromic Substring

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  5. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  6. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  7. substring的用法

    public String substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串.该子字符串从指定的 beginIndex 处开 ...

  8. jQuery之常用且重要方法梳理(target,arguments,slice,substring,data,trigger,Attr)-(一)

    1.jquery  data(name) data() 方法向被选元素附加数据,或者从被选元素获取数据. $("#btn1").click(function(){ $(" ...

  9. leetcode--5. Longest Palindromic Substring

    题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...

随机推荐

  1. Spring boot redis自增编号控制 踩坑

    近段期间,公司 接手一个订单号生成服务,规则的话已经由项目经理他们规定好了,主要是后面的四位数代表的关于当前订单号已经执行第几个了.而这里面有一个要求就是支持分布式.为了实现这个东西,刚开始我使用了r ...

  2. 2.1、Softmax Regression模型

    Softmax Regression模型 由于Logistics Regression算法复杂度低,容易实现等特点,在工业中的到广泛的使用,但是Logistics Regression算法主要用于处理 ...

  3. TX2 默认root用户启动

    Jetpack3.1 修改方式 修改1 gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf 修改后: 修改2 gedit /root/.pro ...

  4. celery实现异步任务

    celery==3.1.25 rabbitmq开启服务 tasks.py代码如下: from celery import Celery broker = 'amqp://guest:guest@loc ...

  5. django笔记-url

    本文章只是用于学习方面的笔记,方便以后避免重复掉坑. 1.模板template的html文件可以根据url.py文件配置的name查找对应的url 2.在template的html文件里里面的url就 ...

  6. Knime读取Jason数据

    Knime ETL 工具 Jason数据解析到DB 1. 下面例子是一段Jason代码 [{,,},{,,},{,,}] 2. 用文本文件存储上面代码. test_jason.txt 3. 用File ...

  7. SpringMVC HandlerMethodArgumentResolver自定义参数转换器

    来源: https://www.cnblogs.com/daxin/p/3296493.html 自定义Spring MVC3的参数映射和返回值映射 + fastjson首先说一下场景:在一些富客户端 ...

  8. lxc 容器基础配置篇

    一, 首先配置lxc需要的网卡断 吧eth0复制一份变为br0 配置br0 配置eth0 重启网卡   /etc/init.d/network restart 安装lxc软件 需要epel源--- y ...

  9. LINUX学习之一:

    学好linux的基础:C语言(GNU C语言与GCC):硬件基础:熟悉操作系统内核代码,熟悉多线程和网络知识.分驱动开发(驱动程序模型即框架)和应用程序开发,目标是驱动开发 驱动开发特点: 不能使用标 ...

  10. ReactJS 页面跳转保存当前scrollTop回来时,自动移动到上次浏览器的位置

    在移动端的操作的时候,相信大家都遇到到这种情况,翻了好几页了,点击一项进去查,然后回来的时候,还想回来我原来的位置. google上也找了一此,有一个组件,但是好像是如果想实现这个功能,页面就得用那个 ...