How to get part of string?

Hey guys I’m having some trouble finding the info I’m looking for here but the idea is to set a string value to only the first part (before the “(” ). When I run this code I come up with an error. Whats Missing here?

// Use this for initialization
	void Start () {
		shipName = (gameObject.ToString());
		int leftPerentheses = shipName.IndexOf ("(");
		shipName = shipName.TrimEnd(leftPerentheses, shipName.Length);
		Debug.Log (shipName);
	}
int leftParenthesis = shipName.IndexOf("(");
string result = shipName.Substring(0, leftParenthesis);
1 Like

Awesome!!! Though I did go around creating a new string called result by just setting ship name directly. :slight_smile:
thank you very much!

Now all I have to do is figure out how to tie 2 strings together into a single return then have it (hopefully) be able to create a new dictionary in my PlayerProperties (Scriptable Object) behavior.

.

Or better yet maybe a single dictionary that uses creative text separation to find the correct data, but either way here’s a link on how to add stings together.

(Modifying post as I go Along)

http://www.bing.com/videos/search?q=add 2 string values together c# youtube&FORM=VIRE1#view=detail&mid=D50660F8C7F5A652963AD50660F8C7F5A652963A

what if i need the part after? i dont need the part before lol

  • Please do not necro old threads.
  • Please read them through, click on the link which contains the text substring and read how you can use it.
1 Like