複数の文字がある場合に、IndexOfとSubStringを使用して特定の文字を選択するにはどうすればよいですか?これが私の問題です。パス「C:\ Users \ Jim \ AppData \ Local \ Temp \」を使用して、「Temp」の部分を削除したいと思います。「C:\ Users \ Jim \ AppData \ Local \」だけを残して以下のコードで問題を解決しましたが、これは「Temp」フォルダーが実際には「Temp」と呼ばれていることを前提としています。もっと良い方法はありますか?ありがとう
if (Path.GetTempPath() != null) // Is it there?{
tempDir = Path.GetTempPath(); //Make a string out of it.
int iLastPos = tempDir.LastIndexOf(@"\");
if (Directory.Exists(tempDir) && iLastPos > tempDir.IndexOf(@"\"))
{
// Take the position of the last "/" and subtract 4.
// 4 is the lenghth of the word "temp".
tempDir = tempDir.Substring(0, iLastPos - 4);
}}