文档库 最新最全的文档下载
当前位置:文档库 › verilog中reg和wire类型的区别和用法 2

verilog中reg和wire类型的区别和用法 2

verilog中reg和wire类型的区别和用法 2
verilog中reg和wire类型的区别和用法 2

reg相当于存储单元,wire相当于物理连线

Verilog 中变量的物理数据分为线型和寄存器型。这两种类型的变量在定义时要设置位宽,缺省为1位。变量的每一位可以是0,1,X,Z。其中x代表一个未被预置初始状态的变量或者是由于由两个或多个驱动装置试图将之设定为不同的值而引起的冲突型线型变量。z代表高阻状态或浮空量。

线型数据包括wire,wand,wor等几种类型在被一个以上激励源驱动时,不同的线型数据有各自决定其最终值的分辨办法。

两者的区别是:即存器型数据保持最后一次的赋值,而线型数据需要持续的驱动

输入端口可以由net/reg驱动,但输入端口只能是net;输出端口可以使net/r eg类型,输出端口只能驱动net;若输出端口在过程块中赋值则为reg型,若在过程块外赋值则为net型

用关键词inout声明一个双向端口, inout端口不能声明为寄存器类型,只能是net类型。

********************************************************************* ********************************************************************* *********

wire表示直通,即只要输入有变化,输出马上无条件地反映;reg表示一定要有触发,输出才会反映输入。

不指定就默认为1位wire类型。专门指定出wire类型,可能是多位或为使程序易读。wire只能被assign连续赋值,reg只能在initial和always 中赋值。wire使用在连续赋值语句中,而reg使用在过程赋值语句中。

在连续赋值语句中,表达式右侧的计算结果可以立即更新表达式的左侧。在理解上,相当于一个逻辑之后直接连了一条线,这个逻辑对应于表达式的右侧,而这条线就对应于wire。在过程赋值语句中,表达式右侧的计算结果在某种条件的触发下放到一个变量当中,而这个变量可以声明成reg类型的。根据触发条件的不同,过程赋值语句可以建模不同的硬件结构:如果这个条件是时钟的上升沿或下降沿,那么这个硬件模型就是一个触发器;如果这个条件是某一信号的高电平或低电平,那么这个硬件模型就是一个锁存器;如果这个条件是赋值语句右侧任意操作数的变化,那么这个硬件模型就是一个组合逻辑。

输入端口可以由wire/reg驱动,但输入端口只能是wire;输出端口可以使wire/reg类型,输出端口只能驱动wire;若输出端口在过程块中赋值则为reg型,若在过程块外赋值则为net型。用关键词inout声明一个双向端口, in out端口不能声明为reg类型,只能是wire类型;输入和双向端口不能声明为寄存器类型。

简单来说硬件描述语言有两种用途:1、仿真,2、综合。

对于wire和reg,也要从这两个角度来考虑。

********************************************************************* ************

从仿真的角度来说,HDL语言面对的是编译器(如Modelsim等),相当于软件思路。

这时:

wire对应于连续赋值,如assign

reg对应于过程赋值,如always,initial

********************************************************************* ************

从综合的角度来说,HDL语言面对的是综合器(如DC等),要从电路的角度来考虑。

这时:

1、wire型的变量综合出来一般是一根导线;

2、reg变量在always块中有两种情况:

(1)、always后的敏感表中是(a or b or c)形式的,也就是不带时钟边沿的,综合出来还是组合逻辑

(2)、always后的敏感表中是(posedge clk)形式的,也就是带边沿的,综合出来一般是时序逻辑,会包含触发器(Flip-Flop)

在设计中,输入信号一般来说你是不知道上一级是寄存器输出还是组合逻辑输出,那么对于本级来说就是一根导线,也就是wire型。而输出信号则由你自己来决定是寄存器输出还是组合逻辑输出,wire型、reg型都可以。但一般的,整个设计的外部输出(即最顶层模块的输出),要求是寄存器输出,较稳定、扇出能力也较好。

********************************************************************* ********************************************************************* ****

Well I had this doubt when I was learning Verilog: What is the differ ence between reg and wire? Well I won't tell stories to explain this, rather I will give you some examples to show the difference.

There is something else about wire which sometimes confuses. wire data types can be used for connecting the output port to the actual driver. Below is the code which when synthesized gives a AND gate as output, as we know a AND gate can drive a load.

view plaincopy to clipboardprint?

module wire_example( a, b, y);

input a, b;

output y;

wire a, b, y;

assign y = a & b;

endmodule

module wire_example( a, b, y);

input a, b;

output y;

wire a, b, y;

assign y = a & b;

endmodule

SYNTHESIS OUTPUT

What this implies is that wire is used for designing combinationa l logic, as we all know that this kind of logic can not store a value. As you can see from the example above, a wire can be assigned a valu e by an assign statement. Default data type is wire: this means that if you declare a variable without specifying reg or wire, it will be a 1-bit wide wire.

Now, coming to reg data type, reg can store value and drive stren gth. Something that we need to know about reg is that it can be used for modeling both combinational and sequential logic. Reg data type c an be driven from initial and always block.

Reg data type as Combinational element

view plaincopy to clipboardprint?

module reg_combo_example( a, b, y);

input a, b;

output y;

reg y;

wire a, b;

always @ ( a or b)

begin

y = a & b;

end

endmodule

module reg_combo_example( a, b, y);

input a, b;

output y;

reg y;

wire a, b;

always @ ( a or b)

begin

y = a & b;

end

endmodule

SYNTHESIS OUTPUT

This gives the same output as that of the assign statement, with the only difference that y is declared as reg. There are distinct advanta ges to have reg mode LED as combinational element; reg type is useful when a "case" statement is required (refer to the Verilog section for more on this).

To model a sequential element using reg, we need to have edge sen sitive variables in the sensitivity list of the always block.

Reg data type as Sequential element

view plaincopy to clipboardprint?

module reg_seq_example( clk, reset, d, q);

input clk, reset, d;

output q;

reg q;

wire clk, reset, d;

always @ (posedge clk or posedge reset)

if (reset) begin

q <= 1'b0;

end else begin

q <= d;

end

endmodule

module reg_seq_example( clk, reset, d, q);

input clk, reset, d;

output q;

reg q;

wire clk, reset, d;

always @ (posedge clk or posedge reset)

if (reset) begin

q <= 1'b0;

end else begin

q <= d;

end

endmodule

SYNTHESIS OUTPUT

There is a difference in the way we assign to reg when modeling c ombinational logic: in this logic we use blocking assignments while m odeling sequential logic we use nonblocking ones.

From the college days we know that wire is something which connec ts two points, and thus does not have any driving strength. In the fi gure below, in_wire is a wire which connects the AND gate input to th e driving source, clk_wire connects the clock to the flip-flop input, d_wire connects the AND gate output to the flip-flop D input

C# string.format用法详解

C#中string.format用法详解 这篇文章主要介绍了C#中string.format用法,以实例形式较为详细的讲述了string.format格式化的各种用法,非常具有实用价值,需要的朋友可以参考下 本文实例总结了C#中string.format用法。分享给大家供大家参考。具体分析如下:String.Format 方法的几种定义: String.Format (String, Object) 将指定的 String 中的格式项替换为指定的 Object 实例的值的文本等效项。 String.Format (String, Object[]) 将指定 String 中的格式项替换为指定数组中相应 O bject 实例的值的文本等效项。 String.Format (IFormatProvider, String, Object[]) 将指定 String 中的格式项替换为指定数组中相应 Object 实例的值的文本等效项。指定的参数提供区域性特定的格式设置信息。 String.Format (String, Object, Object) 将指定的 String 中的格式项替换为两个指定的 Object 实例的值的文本等效项。 String.Format (String, Object, Object, Object) 将指定的 String 中的格式项替换为三个指定的 Object 实例的值的文本等效项。 常用的格式化数值结果表

常用的几种实例 1、字符串的数字格式 复制代码代码如下: string str1 =string.Format("{0:N1}",56789); //resul t: 56,789.0 string str2 =string.Format("{0:N2}",56789); //res ult: 56,789.00 string str3 =string.Format("{0:N3}",56789); //res ult: 56,789.000 string str8 =string.Format("{0:F1}",56789); //res ult: 56789.0 string str9 =string.Format("{0:F2}",56789); //res ult: 56789.00 string str11 =(56789 / 100.0).ToString("#.##"); //result: 567.89 string str12 =(56789 / 100).ToString("#.##"); //resul t: 567

java 字符串常用函数及其用法

java中的字符串也是一连串的字符。但是与许多其他的计算机语言将字符串作为字符数组处理不同,Java将字符串作为String类型对象来处理。将字符串作为内置的对象处理允许Java提供十分丰富的功能特性以方便处理字符串。下面是一些使用频率比较高的函数及其相关说明。 String相关函数 1)substring() 它有两种形式,第一种是:String substring(int startIndex) 第二种是:String substring(int startIndex,int endIndex) 2)concat() 连接两个字符串 例:String s="Welcome to "; String t=s.concat("AnHui"); 3)replace() 替换 它有两种形式,第一种形式用一个字符在调用字符串中所有出现某个字符的地方进行替换,形式如下: String replace(char original,char replacement) 例如:String s=”Hello”.replace(’l',’w'); 第二种形式是用一个字符序列替换另一个字符序列,形式如下: String replace(CharSequence original,CharSequence replacement) 4)trim() 去掉起始和结尾的空格 5)valueOf() 转换为字符串 6)toLowerCase() 转换为小写 7)toUpperCase() 转换为大写 8)length() 取得字符串的长度 例:char chars[]={’a',’b’.’c'}; String s=new String(chars); int len=s.length(); 9)charAt() 截取一个字符 例:char ch; ch=”abc”.charAt(1); 返回值为’b’ 10)getChars() 截取多个字符 void getChars(int sourceStart,int sourceEnd,char target[],int targetStart) sourceStart 指定了子串开始字符的下标 sourceEnd 指定了子串结束后的下一个字符的下标。因此,子串包含从sourceStart到sourceEnd-1的字符。

函数调用参数传递类型(java)的用法介绍.

函数调用参数传递类型(java)的用法介绍. java方法中传值和传引用的问题是个基本问题,但是也有很多人一时弄不清。 (一)基本数据类型:传值,方法不会改变实参的值。 public class TestFun { public static void testInt(int i){ i=5; } public static void main(String[] args) { int a=0 ; TestFun.testInt(a); System.out.println("a="+a); } } 程序执行结果:a=0 。 (二)对象类型参数:传引用,方法体内改变形参引用,不会改变实参的引用,但有可能改变实参对象的属性值。 举两个例子: (1)方法体内改变形参引用,但不会改变实参引用,实参值不变。 public class TestFun2 { public static void testStr(String str){ str="hello";//型参指向字符串“hello” } public static void main(String[] args) { String s="1" ;

TestFun2.testStr(s); System.out.println("s="+s); //实参s引用没变,值也不变 } } 执行结果打印:s=1 (2)方法体内,通过引用改变了实际参数对象的内容,注意是“内容”,引用还是不变的。 import java.util.HashMap; import java.util.Map; public class TestFun3 { public static void testMap(Map map){ map.put("key2","value2");//通过引用,改变了实参的内容 } public static void main(String[] args) { Map map = new HashMap(); map.put("key1", "value1"); new TestFun3().testMap(map); System.out.println("map size:"+map.size()); //map内容变化了 } } 执行结果,打印:map size:2 。可见在方法testMap()内改变了实参的内容。 (3)第二个例子是拿map举例的,还有经常涉及的是 StringBuffer : public class TestFun4 {

Java中string的相关函数

Java中string的相关函数 字串与字元 文字字串是一个相当基本且经常被使用到的资料型态,然而在Java 中字串不象char、int 与float 一样是个基本资料型态,而是使用https://www.wendangku.net/doc/36903048.html,ng.String 类别来加以表示,该类别定义了许多有用的方法来操作字串。String 物件是固定不变的(immutable):一旦一个String 物件被建立了,则没有任何方法可以改变它所代表的文字,因此,每个运作字串的方法会传回一个新的String 物件,而所修正过后的字串便是储存在此新物件里。 以下的程式码展示了你可以对字串所执行的运作: // 建立字串 String s = "Now "; // String 物件有个特殊的写法 String t = s + "is the time. "; // 使用+ 运算子来串连字串 String t1 = s + " " + 23.4; // + 将其它值转换为字串 t1 = String.valueOf( 'c '); // 从字元值获得对应的字串 t1 = String.valueOf(42); // 获得整数或其他任何数值的字串版本 t1 = Object.toString(); // 使用toString() 将物件转换为字串 // 字串长度 int len = t.length(); // 字串中的字元数:16 // 字串中的子字串 String sub = t.substring(4); // 传回从char 4 到最后的子字串:"is the time. " sub = t.substring(4, 6); // 传回chars 4 与5:"is " sub = t.substring(0, 3); // 传回chars 0 到2:"Now " sub = t.substring(x, y); // 传回从位置x 到y-1 间的子字串 int numchars = sub.length(); // 子字串的长度永远是(y-x) // 从一个字串中撷取(extract)出字元 char c = t.charAt(2); // 取得t 的第三个字元:w char[] ca = t.toCharArray(); // 将字串转换为一个字元阵列 t.getChars(0, 3, ca, 1); // 将t 中的前三个字元放到ca[1] 到ca[3] 中 // 大小写转换 String caps = t.toUpperCase(); // 转换为大写 String lower = t.toLowerCase(); // 转换为小写 // 字串比较 boolean b1 = t.equals( "hello "); // 传回flase:两字串并不相等 boolean b2 = t.equalsIgnoreCase(caps); // 忽略大小写的字串比较:true boolean b3 = t.startsWith( "Now "); // 传回true boolean b4 = t.endsWith( "time. "); // 传回true int r1 = https://www.wendangku.net/doc/36903048.html,pareTo( "Pow "); // 传回值<0:s 在"Pow "之前 int r2 = https://www.wendangku.net/doc/36903048.html,pareTo( "Now "); // 传回值0:两字串相等

C#所有处理字符串函数和用法

C#字符串函数大全 C#字符串函数大全将包括Len Len(string|varname) 、Trim Trim(string) 、Ltrim Ltrim(string)等多项内容 LenLen(string|varname)返回字符串内字符的数目,或是存储一变量所需的字节数。 TrimTrim(string)将字符串前后的空格去掉 LtrimLtrim(string)将字符串前面的空格去掉 RtrimRtrim(string)将字符串后面的空格去掉 MidMid(string,start,length)从string字符串的start字符开始取得length长度的字符串,如果省略第三个参数表示从start字符开始到字符串结尾的字符串 LeftLeft(string,length)从string字符串的左边取得length长度的字符串 RightRight(string,length)从string字符串的右边取得length长度的字符串 LCaseLCase(string)将string字符串里的所有大写字母转化为小写字母 UCaseUCase(string)将string字符串里的所有大写字母转化为大写字母 StrCompStrComp(string1,string2[,compare])返回string1字符串与string2字符串的比较结果,如果两个字符串相同,则返回0,如果小于则返回-1,如果大于则返回1 InStrInStr(string1,string2[,compare])返回string1字符串在string2字符串中第一次出现的位置 SplitSplit(string1,delimiter[,count[,start]])将字符串根据delimiter拆分成一维数组,其中delimiter用于标识子字符串界限。如果省略,使用空格("")作为分隔符。

JAVA复习题(学生)

《Java程序设计》课程试卷 1.使用Java语言编写的源程序保存时的文件扩展名是()。 (A).class (B).java(C).cpp (D).txt 2.设int a=-2,则表达式a>>>3的值为()。 (A)0 (B)3 (C)8(D)-1 3.设有数组的定义int[] a = new int[3],则下面对数组元素的引用错误的是()。 (A)a[0]; (B)a[a.length-1]; (C)a[3]; (D)int i=1;a[i]; 4.在类的定义中可以有两个同名函数,这种现象称为函数()。 (A)封装(B)继承 (C)覆盖(D)重载 5.在类的定义中构造函数的作用是()。 (A)保护成员变量(B)读取类的成员变量 (C)描述类的特征(D)初始化成员变量 6.下面关键字中,哪一个不是用于异常处理语句()。 (A)try (B)break (C)catch (D)finally 7.类与对象的关系是()。 (A)类是对象的抽象(B)对象是类的抽象 (C)对象是类的子类(D)类是对象的具体实例 8.下面哪一个是Java中不合法的标识符()。 (A)$persons (B)twoNum (C)_myVar (D)*point 9.为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )。 (A)static void method( ) (B)public void method( ) (C)final void method( ) (D)abstract void method( ) 11.Java源文件和编译后的文件扩展名分别为() (A) .class和 .java(B).java和 .class (C).class和 .class(D) .java和 .java 12.在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( )方法来完成一些画图操作。 (A) start( ) (B) stop( ) (C) init( ) (D) paint( ) 13.对于一个Java源文件,import, class定义以及package正确的顺序是: (A) package,import,class(B) class,import,package (C) import,package,class(D) package,class,import 14.下面哪个是非法的: (A) int I = 32;(B) float f = 45.0; (C) double d = 45.0;(D) char c = ‘u’;//符号错 15.Java语言使用的字符码集是 (A) ASCII (B) BCD (C) DCB (D) Unicode 16. 如果一个类的成员变量只能在所在类中使用,则该成员变量必须使用的修饰是 (A) public (B) protected (C) private(D) static 17.下面关于main方法说明正确的是

JS字符串的拼接用法

1 toGMTString() 方法可根据格林威治时间 (GMT) 把 Date 对象转换为字符串,并返回结果。 语法 dateObject.toGMTString() 返回值 dateObject 的字符串表示。此日期会在转换为字符串之前由本地时区转换为GMT 时区。 提示和注释 不赞成使用此方法。请使用 toUTCString() 取而代之!! 实例 例子 1 在本例中,我们将把今天的日期转换为(根据 GMT)字符串: 输出: Tue, 21 Feb 2017 10:51:34 UTC 例子 2 在下面的例子中,我们将把具体的日期转换为(根据 GMT)字符串: 输出: Wed, 20 Jul 1983 17:15:00 UTC 2 toLocaleDateString() 方法可根据本地时间把 Date 对象的日期部分转换为字符串,并返回结果。 语法 dateObject.toLocaleDateString() 返回值 dateObject 的日期部分的字符串表示,以本地时间区表示,并根据本地规则格式化 3 toLocaleLowerCase() 方法用于把字符串转换为小写。 语法 stringObject.toLocaleLowerCase() 返回值 一个新的字符串,在其中 stringObject 的所有大写字符全部被转换为了小写字符。 说明 与 toLowerCase() 不同的是,toLocaleLowerCase() 方法按照本地方式把字符串转换为小写。只有几种语言(如土耳其语)具有地方特有的大小写映射,所有该方法的返回值通常与 toLowerCase() 一样。 实例

tostring方法

【1】基本包装类型-布尔型 var obj = new Boolean(true); console.log(obj.toString()); //“真” console.log(typeof obj.toString()); //字符串 //如果是包装器类型的原始类型,则返回原始原始类型值 var a = true; console.log(a.toString()); //“真” console.log(typeof a.toString()); //字符串 如果它是与基本包装器类型相对应的基本类型,则返回原始值。但是,这并不意味着基本类型具有tostring()方法(基本类型不是对象并且没有任何方法),而是在读取基本类型值时,后台将创建与基本类型相对应的对象包装器类型,以便调用某些方法。因此,当基本类型“调用” tostring()方法时,它实际上会创建相应的基本包装类型,该基本包装类型将调用tostring()并最终返回其相应的字符串。似乎基本类型调用tostring()方法来获取相应的字符串。 【2】基本包装类型-串状 var obj = new String(“ hello”); console.log(obj.toString()); //你好 console.log(typeof obj.toString()); //字符串 //如果是包装器类型的原始类型,则返回原始原始类型值 var a =“ hello”; console.log(a.toString()); //你好

console.log(typeof a.toString()); //字符串 与[1]相同,字符串基本包装类型和调用tostring()方法的基本类型返回相应的字符串 【3】基本包装类型-编号类型 var obj = new Number(“ 123”); console.log(obj.toString()); // 123 console.log(typeof obj.toString()); //字符串 //如果是包装器类型的原始类型,则返回原始原始类型值 var a = 123; console.log(a.toString()); // 123 console.log(typeof a.toString()); //字符串 与[1]相同,通过调用数字基本包装类型和基本类型的tostring ()方法返回相应的字符串。 请注意,如果直接调用整数,则应加上方括号,否则将报告错误。因为整数后的点被识别为小数点。浮点不报告错误。 console.log(123.toString()); //未捕获的SyntaxError console.log((123).toString()); //“ 123” console.log(12.3.toString()); //“ 12.3” 此外,数字tostring()方法可以接收转换基数的表示形式(可选,2-36中的任何数字),并且如果未指定此参数,则转换规则将基于十进制。 var n = 33;

ToString()格式大全

我的地盘 我的地盘,我做主。 主页博客相册|个人档案 |好友查看文章 C#中ToString格式大全 2008-12-31 10:20 C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString("E") 2.500000E+005 F 固定点 25.ToString("F2") 25.00 G 常规 2.5.ToString("G") 2.5 N 数字 2500000.ToString("N")

2,500,000.00 X 十六进制 255.ToString("X") FF formatCode 是可选的格式化代码字符串。(详细内容请搜索“格式化字符串”查看) 必须用“{”和“}”将格式与其他字符分开。如果恰好在格式中也要使用大括号,可以用连续的两个大括号表示一个大括号,即:“{{”或者“}}”。 常用格式举例: (1) int i=12345; this.textBox1.Text=i.ToString(); //结果 12345(this指当前对象,或叫当前类的实例) this.textBox2.Text=i.ToString("d8"); //结果 00012345 (2) int i=123; double j=123.45; string s1=string.Format("the value is {0,7}",i); string s2=string.Format("the value is {0,73}",j); this.textBox1.Text=s1 ; //结果 the value is 123

string函数的使用

import java.io.UnsupportedEncodingException; import java.util.*; public class Main { public static void main(String[] args) throws UnsupportedEncodingException { // TODO 自动生成的方法存根 String str="China University of Petroleum!!!"; int length=str.length(); //字符串长度函数 if(!str.isEmpty()) //判断字符串是否为空 System.out.println("The length of str is:"+length); try { char ch=str.charAt(15); //返回index指定的字符 System.out.println("The character at the specified index is:"+ch); ch=str.charAt(55); //异常范围 } catch(IndexOutOfBoundsException e) { //异常处理 System.out.println(e.getMessage()); } try { int number=str.codePointAt(25); //返回index指定字符1的万国码 System.out.println("The character codePoint at the specified index is:"+number); number=str.codePointAt(55); //异常范围

类、属性、方法的格式

案例: 定义一个“富婆类”,属性name 、money。行为一(无参数无返回):跑步喝水;行为二(无参数有返回值):收快递;行为三(有参数有返回):买烟smoke;行为四(有参数无返回):施舍money 施舍apple。 定义富婆类: Public class 富婆类{ //定义属性 String name; int money; /*方法类型一:无参数无返回。 格式: public void 方法名(){ //方法体 }*/ Public void 跑步(){ System.out.println(name+”在跑步”); } /*方法类型二:无参数有返回。 格式: Public 返回值类型方法名(){ //方法体 return 值;//return值类型必须和返回值类型相同 } public String 收快递(){ String str=”德玛西亚皮肤”; return str; //打印对象的信息:方法名和返回值不能改 /*每一类都有一个打印对象的信息的方法返回值类型一定是String ,方法名一定是toString,不能修改。*/ public String toString(){ return “自我介绍”+name+money; } /*方法类型三:有参数有返回。 格式: public 返回值类型方法名(参数1,参数2,参数3,……){//参数可以有多个,中间用,隔开。 //方法体 return值 }

public String 买烟(int money){ String smoke; if(money>=25){ smoke = "芙蓉王"; }else{ smoke = "相思鸟"; } return smoke; } /*方法类型四:有参数无返回。 格式: public 返回值类型方法名(参数1,参数2,参数3,……){ //方法体} } public String 施舍(Sring apple,int mone){ System.out.println(name+”施舍给别人”+apple+”和”+money+”元钱”); } } 测试类: public class Test1{ public static void main(String[] args){ 富婆类fp=new 富婆类(); https://www.wendangku.net/doc/36903048.html,=”芙蓉姐姐”; fp.money=100*100*100; //输出类的所有属性的属性值:自我介绍 //方法一: //System.out.println("自我介绍"+https://www.wendangku.net/doc/36903048.html,+"\t"+fb.money); //方法二:toString方法(必须配合使用自定义类中的public String toString()System.out.println(fb.toString());【也可以这样写:System.out.println(fp );//词句话会自动调用toString()方法】。 //(方法类型一的调用)调用无参数无返回值的方法 fp.喝水(); //(方法类型二的调用)调用无参数有返回值的方法☆必须接受返回值才能输出返回的东西 /*String s = fb.收快递(); System.out.println(s); 输出数据等价于下面一句话:*/ System.out.println(fp.收快递());//配合自定义类中的return使用

C#_tostring的用法

format Code 是可选的格式化代码字符串。(详细内容请搜索“格式化字符串”查看) 必须用“{”和“}”将格式与其他字符分开。如果恰好在格式中也要使用大括号,可以用连续的两个大括号表示一个大括号,即:“{{”或者“}}”。 常用格式举例: (1)int i=12345; this.textBox1.Text=i.ToSt ring(); //结果12345(this指当前对象,或叫当前类的实例) this.textBox2.Text=i.ToSt ring("d8"); //结果00012345 (2)int i=123; double j=123.45;

string s1=st ring.F ormat("t he value is {0,7:d}",i); string s2=st ring.F ormat("t he value is {0,7:f3}",j); this.textBox1.Text=s1 ; //结果the value is 123 this.textBox2.Text=s2; //结果the value is 123.450 (3)double i=12345.6789; this.textBox1.Text=i.ToSt ring("f2"); //结果12345.68 this.textBox2.Text=i.ToSt ring("f6"); //结果12345.678900 (4)double i=12345.6789; this.textBox1.Text=i.ToSt ring("n"); //结果12,345.68 this.textBox2.Text=i.ToSt ring(“n4”); //结果12,345.6789 (5)double i=0.126; string s=string.F ormat("the value is {0:p}",i); this.textBox1.Text=i.ToSt ring("p"); //结果12.6% this.textBox2.Text=s; //结果the value is 12.6% (6)DateTime dt=new DateTime(2003,5,25); this.textBox1.Text=dt.ToString("yy.M.d"); //结果03.5.25 th is.textBox2.Text=dt.ToString(“yyyy年M月”); //结果2003年5月 Convert.ToDateTime("2005/12/22 22:22:22").ToString("yyyy/ MM/dd HH:mm:ss") "2005/12/22 22:22:22" (7)int i=123; double j=123.45; string s=string.F ormat("i:{0,-7},j:{1,7}",i,j); //-7表示左对齐,占7位 this.textBox1.Text=s ; //结果i:123 ,j: 123.45 DateTime.ToString()用法详解 我们经常会遇到对时间进行转换,达到不同的显示效果,默认格式为:2006-6-6 14:33:34 如果要换成成200606,06-2006,2006-6-6或更多的格式该怎么办呢? 这里将要用到:DateTime.ToString的方法(String, IFormatProvider)

字符串常用方法

计算字符串的长度* string myString = "This is a test!"; Console.WriteLine("Text is :{0}",myString); Console.WriteLine("Text's long is :{0}",myString.Length); * 转换大小写* myString = myString.ToLower(); //所有字符转换成小写 myString = myString.ToUpper(); //所有字符转换成大写 * 删除前后空格* myString = myString.Trim(); //同时删除字符串前后的空格 char[] trimChars = {' ','e','s'}; //准备删除的字符 myString = myString.Trim(trimChars); //删除所有指定字符 myString = myString.TrimEnd(); //删除字符串后的空格 myString = myString.TrimStart(); //删除字符串前的空格 * 添加空格* myString = myString.PadRight(14,' '); //当字符串长度不够14位时,在他的右边用指定字符填充myString = myString.PadLeft(14,' '); //当字符串长度不够14位时,在他的左边用指定字符填充 * 拆分字符串* string[] nStrs = myString.Split(' ',3); //按照空格进行拆分,并且返回前三个字符串 * 获取子字符串* string a = myString.Substring(2,2); //从myString字符串的第三位开始获取两个字符,因为索引 起始位是0 * 替换字符串中的字符* string a = myString.Replace("i","o"); //将这个字符串中的所有“i”替换成“o” C#中字符串实际上是Char变量的只读数组。可以用下面的方法访问字符串中每一个字符,但是不能修 改他们。 string myString = "This is a test!"; foreach (char myChar in myString) { Console.Write("{0}",myChar); } 要想得到一个可读写的字符数组,你可以这样。 char[] myChars = myString.ToCharArray();

JAVA基础——toString()方法

JAVA基础——toString()方法 toString()方法返回反映这个对象的字符串 因为to String方法是Object里面已经有了的方法,而所有类都是继承Object,所以“所有对象都有这个方法”。 它通常只是为了方便输出,比如System.out.println(xx),括号里面的“xx”如果不是String类型的话,就自动调用xx的toString()方法 总而言之,它只是sun公司开发java的时候为了方便所有类的字符串操作而特意加入的一个方法 一toString()方法 【1】undefined和null没有toString()方法 undefined.toString();//错误null.toString();//错误 【2】布尔型数据true和false返回对应的'true'和'false' true.toString();//'true'false.toString();//'false' Boolean.toString();//"function Boolean() { [native code] }" 【3】字符串类型原值返回 '1'.toString();//'1'''.toString();//'''abc'.toString();//'abc' String.toString();//"function String() { [native code] }" 【4】数值类型的情况较复杂 Number.toString();//"function Number() { [native code] }" 1、正浮点数及NaN、Infinity加引号返回

JPA 各种基本用法

JPA 各种基本用法 JPQL就是一种查询语言,具有与SQL 相类似的特征,JPQL 是完全面向对象的,具备继承、多态和关联等特性,和hibernate HQL很相似。 查询语句的参数 JPQL 语句支持两种方式的参数定义方式: 命名参数和位置参数。。在同一个查询语句中只允许使用一种参数定义方式。 命令参数的格式为:“ : + 参数名” 例: Query query = em.createQuery("select p from Person p where p.personid=:Id "); query.setParameter("Id",new Integer(1)); 位置参数的格式为“ ?+ 位置编号” 例:

Query query = em.createQuery("select p from Person p where p.personid=?1 "); query.setParameter(1,new Integer(1)); 如果你需要传递java.util.Date 或java.util.Calendar 参数进一个参数查询,你需要使用一个特殊的setParameter() 方法,相关的setParameter 方法定义如下: public interface Query { // 命名参数查询时使用,参数类型为java.util.Date Query setParameter(String name, java.util.Date value, TemporalType temporalType); // 命名参数查询时使用,参数类型为java.util.Calendar

简单串口通讯_参数设置

using System; using System.Collections.Generic; using https://www.wendangku.net/doc/36903048.html,ponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 串口通讯 { public partial class frmDataExchange : Form { public frmDataExchange() { InitializeComponent(); } private void frmDataExchange_Load(object sender, EventArgs e) { int index; int count = 1; for (int i = 1; i <= 10; i++) { this.cboxCOM.Items.Add("COM" + i); } for (int i = 1; i < 10; i++) { index = count * 300; this.cboxBaudRate.Items.Add(index); count *= 2; } this.cboxCOM.SelectedIndex = 0; this.cboxBaudRate.SelectedIndex = 0; this.txtSend.Enabled = false; this.txtRecieve.Enabled = false; this.btnSend.Enabled = false; } private void cboxCOM_SelectedIndexChanged(object sender, EventArgs e) {

C#中ToString格式大全

https://www.wendangku.net/doc/36903048.html, ToString()格式汇总 formatCode是可选的格式化代码字符串。(详细内容请搜索“格式化字符串”查看) 必须用“{”和“}”将格式与其他字符分开。如果恰好在格式中也要使用大括号,可以用连续的两个大括号表示一个大括号,即:“{{”或者“}}”。 常用格式举例: (1)inti=12345; this.textBox1.Text=i.ToString(); //结果12345(this指当前对象,或叫当前类的实例) this.textBox2.Text=i.ToString("d8"); //结果00012345 (2)inti=123; double j=123.45; string s1=string.Format("the value is {0,7:d}",i); string s2=string.Format("the value is {0,7:f3}",j); this.textBox1.Text=s1 ; //结果the value is 123 this.textBox2.Text=s2; //结果the value is 123.450 (3)double i=12345.6789; this.textBox1.Text=i.ToString("f2"); //结果12345.68

this.textBox2.Text=i.ToString("f6"); //结果12345.678900 (4)double i=12345.6789; this.textBox1.Text=i.ToString("n"); //结果12,345.68 this.textBox2.Text=i.ToString(“n4”); //结果12,345.6789 (5)double i=0.126; string s=string.Format("the value is {0:p}",i); this.textBox1.Text=i.ToString("p"); //结果12.6% this.textBox2.Text=s; //结果the value is 12.6% (6)DateTimedt =new DateTime(2003,5,25); this.textBox1.Text=dt.ToString("yy.M.d"); //结果03.5.25 this.textBox2.Text=dt.ToString(“yyyy年M月”); //结果2003年5月 Convert.ToDateTime("2005/12/22 22:22:22").ToString("yyyy/MM/ddHH:mm:ss") "2005/12/22 22:22:22" (7)inti=123; double j=123.45; string s=string.Format("i:{0,-7},j:{1,7}",i,j); //-7表示左对齐,占7位 this.textBox1.Text=s ; //结果i:123 ,j: 123.45 DateTime.ToString()用法详解 我们经常会遇到对时间进行转换,达到不同的显示效果,默认格式为:2006-6-6 14:33:34 如果要换成成200606,06-2006,2006-6-6或更多的格式该怎么办呢? 这里将要用到:DateTime.ToString的方法(String, IFormatProvider) 示例: using System; using System.Globalization; String format="D"; DateTime date=DataTime.Now;

相关文档