Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列をトリミングして、特定の単語の後に出現するすべての単語を削除したいと考えています。
例- 文字列に「very」テキストが含まれている場合
string mySentence=" Today is very nice day! "; if (mysentence.Contains(very)) { //remove everything that starts with 'very' until rest of the line.. }
結果は次のようになります。
今日は
まず、必要な単語を使用して分割します
string[] splits = mysentence.Split("very");
"very" が文字列内にあることはすでに確認済みなので、これで 2 つの文字列が得られます。最初のもの(「非常に」の前の分割)が必要です。そのスペースから余分なスペースを削除する必要があります。
string result = splits[0].Trim();