Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string at first space [closed]

Tags:

c#

split

I'm trying to split a string at the first space and only keep the 2nd half. So if the input was "1. top of steel", the output would be "top of steel". I'm working with a few different examples from here and I cant get it to work. Thoughts? Thanks.

like image 938
topofsteel Avatar asked Sep 06 '25 14:09

topofsteel


2 Answers

var myString = "1. top of steel";
var newString = myString.Remove(0, myString.IndexOf(' ') + 1);
like image 197
Daniel Bidulock Avatar answered Sep 08 '25 19:09

Daniel Bidulock


This is easily accomplished using Substring:

string myString = "1. top of steel";
string newString = myString.Substring(myString.IndexOf(' ') + 1);

This will give you a new string starting after the first space.

like image 43
jzworkman Avatar answered Sep 08 '25 21:09

jzworkman