string manipulation in game development-C # in Unity -
◇ 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
string manipulation in game development-C # in Unity -的更多相关文章
- VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟
C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...
- Bash String Manipulation Examples – Length, Substring, Find and Replace--reference
In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...
- CodeForces 159c String Manipulation 1.0
String Manipulation 1.0 Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on Cod ...
- HoloLens开发手记 - Unity development overview 使用Unity开发概述
Unity Technical Preview for HoloLens最新发行版为:Beta 24,发布于 09/07/2016 开始使用Unity开发HoloLens应用之前,确保你已经安装好了必 ...
- leetcode@ [68] Text Justification (String Manipulation)
https://leetcode.com/problems/text-justification/ Given an array of words and a length L, format the ...
- 对std::string和std::wstring区别的解释,807个赞同,有例子
807down vote string? wstring? std::string is a basic_string templated on a char, and std::wstring on ...
- Unity性能优化(1)-官方教程The Profiler window翻译
本文是Unity官方教程,性能优化系列的第一篇<The Profiler window>的简单翻译. 相关文章: Unity性能优化(1)-官方教程The Profiler window翻 ...
- Unity自动打包Apk
unity打包apk相对来说比较容易,相信出过的人都明白,出包过程,没有大的难度,一步一操作,一步一等待,繁琐耗时,不懂的人又代替不了.这时候需求就来了,如何简单的一键打包搞定,这个就稍微有点难度,当 ...
- Java String Class Example--reference
reference:http://examples.javacodegeeks.com/core-java/lang/string/java-string-class-example/ 1. Intr ...
随机推荐
- Django基础一
Django基础一 Web框架本质 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演 ...
- python识别验证码
1.tesseract-ocr安装 tesseract-ocr windows下载地址 http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr- ...
- Redis以服务的形式启动
★期望目标:把RedisWatcher安装为windows服务. 安装完成后, 到安装目录下修改watcher.conf. 注意,任何路径都不可包含空格,中文,特殊字符,且全部使用绝对路径 ※配置文件 ...
- 关于maven包冲突的一些思路
在最近的项目中出现了很多包冲突,有时一下子就能猜到错误,但是有写往往需要很久都不能定位问题,尤其是项目人员参差不齐,有时为了方便私自引入一些工具类,而未考虑到项目本身. maven的出现方便了我们的包 ...
- POJ - 2763 Housewife Wind (树链剖分/ LCA+RMQ+树状数组)
题意:有一棵树,每条边给定初始权值.一个人从s点出发.支持两种操作:修改一条边的权值:求从当前位置到点u的最短路径. 分析:就是在边可以修改的情况下求树上最短路.如果不带修改的话,用RMQ预处理LCA ...
- python2.7中的字符编码问题
0. 写在前面 起因:之前写个数据预处理程序的时候遇到了点问题,用re模块的正则查找方法search时总是找不出来(找错了或者出乱码),于是捣鼓捣鼓. 经过:查资料,做实验,发现用utf8编码的str ...
- 完美修改iOS项目名
注意:重命名项目时,记得先备份好一份 1.选中旧项目名,改为新项目名: 选择rename: 2.修改相关文件夹名称: 3.全局搜索旧项目名称,然后替换为新项目名称: 4.经过步骤3的替换,再次全局搜索 ...
- lock关键字的用法
一直以来对于lock关键字的用法都存有疑惑,也从网上看到很多关于他的资料包括MSDN,无奈MSDN讲述的真是让人上火.今天决定小小研究一下 一直都知道lock是锁定某一变量从而实现对某一代码段的独占执 ...
- poj2250
#include<string.h> #include<stdio.h> #include<algorithm> #include<vector> #i ...
- 关于comparable接口
参考博客: https://blog.csdn.net/nvd11/article/details/27393445 第一个例子 @Test public void fun1(){ List list ...