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. mysql 5.7.22 解压缩安装

    1.下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 直接点击下载项 下载后: 2.可以把解压的内容随便放到一个目录,我的是如 ...

  2. Python第一天学习成果

    1.变成可执行程序,在开头需加#!/usr/bin/env python找解释器 2.Python不支持常量,但建议用全大写就表明是常量 3.Unicode:2字节 ASCII:1字节 UTF-8(可 ...

  3. 【原创】elasticsearch入门

    示例 示例一: 示例二: 示例三: 示例四: ES介绍 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Ela ...

  4. LeetCode记录之28——Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  5. vue-awesome-swiper 的 使用

    1.确保 package.json文件中有  "vue-awesome-swiper": "^3.1.3",没有的话install下 2.在main.js配置 ...

  6. POJ - 3233 矩阵套矩阵

    题意:给你矩阵\(A\),求\(S=\sum_{i=1}^{k}A^i\) 构造矩阵 \[ \begin{bmatrix} A & E \\ 0 & E\\ \end{bmatrix} ...

  7. java 上传文件到 ftp 服务器

    1.  java 上传文件到 ftp 服务器 package com.taotao.common.utils; import java.io.File; import java.io.FileInpu ...

  8. 中间件使用之(UA,IP,selenium)的使用

    一.UA池:User-Agent池 - 作用:尽可能多的将scrapy工程中的请求伪装成不同类型的浏览器身份. - 操作流程: 1.在下载中间件中拦截请求 2.将拦截到的请求的请求头信息中的UA进行篡 ...

  9. 第三次 Scrum Meeting

    第三次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/4/7 20:00 60min 新主楼G411 附Github仓库:WEDO 例会照片 工作情况总结(4.5-4. ...

  10. git push的一些坑

    在安装git的时候我们一般会自己设置一个用户名和邮箱,这个一般设置为全局的用户名,如下所示 git config --global user.name "xxx" git conf ...