c# - How to remove strings from a string based on the contents of a string array? -
checks if contains instance of element in mystring. may "sideboard: 1 forest", "sb: 1 mountain", "sb 1 plains", etc. if contain of elements of array, elements followed white space, number, white space, , string: " 1 swamp".
string[] mystring = {"side", "side", "board", "board", "sideboard", "sideboard", "sb", "sb", "sb:", "sb:"}; if(mystring.any(s => something.contains(s))) { // newsomething = instance of element in mystring removed // start of first whitespace. }
i need help removing part of comment in above if statement block.
editthose blunt responses, understand!
i did go through introduction , tried searched relevant stuff couldn't find situation. little programme made personal use, not assignment. not know regular expressions.
as clarification, @ point in programme "something" found contain of elements in "mystring" array, want remove elements start of string in "something".
ex: = "sideboard: 1 within out"
i want remove "mystring" elements origin of string , before number because strings after number may contain elements of "mystring".
also, upon submitting question, instantly figured out way removing: used trimstart() array containing individual characters of elements in "mystring". did wanted kept question more elegant solution. so, intents , purposes, question answered.
thanks help!
string newsomething = something.substring(0, something.indexof(' '));
the above code homecoming string ending @ first instance of space in 'something' string. if there no spaces in 'something' string, there exception.
not sure if looking for, luck.
c# arrays string
No comments:
Post a Comment