c# - Substring with repeating character -


how substring sample combobox items

e11-143 - america           -->    america  jc - political theory       -->    political theory 

i tried this:

string test = combobox1.text.substring(combobox1.text.indexof('-') + 1).trim(); 

but result

e11-143 - america           -->    143 - america  jc - political theory       -->    political theory 

use lastindexof index of last occurrence of character:

string test = combobox1.text.substring(combobox1.text.lastindexof('-') + 1).trim(); 

Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -