letter
using UnityEngine;
using System.Collections;
public class ExLetter1 : MonoBehaviour {
// Use this for initialization
void Start () {
string t1 = "KOREA WORLD";
int pos = FindChar("KOREA WORLD", 'A');
print (t1 + " " + pos);
string t2 = ReplaceChar(t1, 'O', 'Q');
print(t2);
pos = FindString(t1, "EA");
print (pos);
}
// Update is called once per frame
void Update () {
}
int FindChar(string t, char c){
for(int i = 0; i < t.Length; i++){
if(t[i] == c){
return i;
}
}
return -1;
}
string ReplaceChar(string t, char c1, char c2){
string text = " ";
for(int i=0; i < t.Length; i++){
if(t[i] == c1){
text += c2;
}else{
text += t[i];
}
}
return text;
}
int FindString(string t, string s){
bool isOk = false;
for(int i = 0; i < t.Length; i++){
isOk = true;
for(int j = 0; j < s.Length; j++){
if ( t[i + j] != s[j] ){
isOk = false;
break;
}
}
if(isOk == true){
return i;
}
}
return -1;
}
}