◇ string manipulation in game development-C # in Unity -

It is about the various string

● defined as the declaration of a string variable

string s = "string";

※ s leading lowercase

● addition of string

string a = "string A";
string b = "string B";
string c; and add the / / string to each other; c = a + b
a constant to / / variable; c = a + "string C" The plus
to add a variable to the / / constant; c = "string C" + a

● The length of the string

string a = "A string";
int b; b = a.length;

Number of characters is returned. Will be 4 Using the example above 
you will be counted as one full-width characters

● takes out part of the string

string a = "A string";
string b; b = A.Substring ("starting position", and "number of characters to retrieve");

Zero-based starting position 
em will also be counted as one character

b = a.Substring (0, 2); / / from the first two characters → character
(1, 2) b = a.Substring; / / from the second character 3 character string →
​​b = a.Substring (1); / / 3 remaining characters all → string A

● split with a particular character string

string a = "string A \ n string B";
string [] b;
c string; ("\ N" [0]) b = A.Split; with / / line feed code division
c = b [0]; / / "String A" into the c

If you want multiple delimiters, which is possible by the array

string a = "string A \ n string B";
string [] b;
c string;
delimiter / / data; string [] = {KUGIRI "\ r", "\ N"} b = A.Split split at each character in the / / KUGIRI variable; (KUGIRI)
"A string" into the / / c; c = b [0]

○ If you want to delete items only blank 
in Split in fact there is a second argument, if you specify a System.StringSplitOptions.RemoveEmptyEntries there, no variable contents will be deleted after you split

There are three line break in between / /; string a = "string A \ n \ n \ n string B"
string [] b;
string c; b = A.Split ("\ N" [0], System . split / / line feed code; StringSplitOptions.RemoveEmptyEntries). Blank to remove

/ / "String A" b [0] 
"String B" / / b [1] 
/ / enters

● string comparison

I == comparable in principle

string a = "A string"; 

{(a == "string A") if
a match / /
} else {
not / / match
}

• Use the Equals method if you can not compare well

string a = "A string"; 

{(a.equals ("string A")) if
the match / /
} else {
not / / match
}

• It is not possible to compare the variables and only made a declaration

a string; 

if (a == null) {/ / x
}

↓ like this I get an error 
CS0165 error: Use of unassigned local variable `a ' variables to use the if statement, it must be always defined in some cases not. Because it is useless

a string;
int b = 1; if (b == 1) {
a = "initialization";
}
if (a == null) {
Debug.Log ("true");
}

※ It is an error if b is not 1, so may occur state of · null It is a thing with nothing on is instead of a null, then it also can be assigned null

string a = null;

● Substitute a numeric value to a string

· Integer

int a = 123;
string b; b = "" + a;

Minority

float a = 123.45F;
string b; b = "" + a;

● The assignment to a numeric character

• In the case of integer

string a = "123";
int b; TRY {
; (a) b = Int.Parse
catch {}
: (It is an error even when a small number of) when a string is not an integer / / error
}

Will result in an error of less than in the case of a string that can not be converted 
Object reference not set to an instance of an object: NullReferenceException in the case of the Minority

string a = "123.45";
float b; TRY {
; (a) b = Float.Parse
{} catch
: when a string is not a small number / / error
}

○ use the TryParse method if you do not want to raise an exception 
if the integer-

string a = "123";
int b; {if (Int.TryParse (a, b out))
when the / / normal
result of 123 is in the / / b
} else {
/ / error: string (It is an error even when a few) when it is not an integer
0 always contains the / / b
}

• If a small number of

string a = "123.45";
float b; {if (Float.TryParse (a, b out))
when the / / normal
result of 123.45 is in the / / b
} else {
/ / error: string when it is not a small number
0 always contains the / / b
}

● string search

string a = "string A \ n string B";
int b; b = A.IndexOf ('\ N');

Is set to 0 the beginning, the number of characters was first discovered will contain 
is b = 4 in this case, if the character is not found, -1 is entered

(('\ n') == -1 a.IndexOf) {if
there is no / / string
} {else
there is a / / string
}

● switch ~ case statement

; string word = "spring" Switch (Word) { Case "Spring": Case "summer": Case "Autumn": : Case "winter"     case was one of the / / four season     ; break : default     / / it other than     / / Can not be omitted; break } You can not omit the last break of ※. The following error appears when I forget to write error CS0163: Control cannot fall through from one case label to another

● debug output

string debug = "debug string";
Debug.Log (debug);

※ Console window appears in the Window → Console menu

最新文章

  1. 参与github上开源项目的大致流程和注意事项
  2. mac osx 快捷键符号以及意义 触发角:锁屏
  3. 在Android中调用C#写的WebService(附源代码)
  4. Sql Server Row_Number() 学习
  5. Firefly 性能测试 报告
  6. java 内存泄露 学习
  7. 深入理解linux网络技术内幕读书笔记(二)--关键数据结构
  8. 基于spring mvc的图片验证码实现
  9. [C#]使用TcpListener及TcpClient开发一个简单的Chat工具
  10. 9.8、Libgdx的返回键和菜单键捕获
  11. 三机互ping(自己总结)
  12. [BZOJ1984][Luogu4315]月下“毛景树”
  13. 2018-2019-2 网络对抗技术 20165316 Exp5 MSF基础应用
  14. SkylineGlobe 如何实现工程进度管理或者说是对象生命周期管理
  15. restfull环境搭建-helloword(三)
  16. Integer类之缓存
  17. mysql导入导出数据过大命令
  18. Spring总结七:AOP动态代理的实现
  19. poj 1273 ---&&--- hdu 1532 最大流模板
  20. 解决Umbraco中Generated文件夹下面model问题

热门文章

  1. day5笔记 列表 list 增删改查
  2. mysql第三天作业
  3. HDU - 6336 Problem E. Matrix from Arrays (规律+二维前缀和)
  4. 记录一次代码错误,elastic search的INDEX需要使用小写字母
  5. $命令行参数解析模块argparse的用法
  6. 【JavaScript】用JS绘制一个球
  7. Mysql 忘记密码处理配置
  8. React生命周期及事件详解
  9. Spring Cloud2.0之Oauth2环境搭建(授权码模式和密码授权模式)
  10. BFS - 广度优先搜索 - 邻接列表表示法