00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 using System;
00018 using System.Collections.Generic;
00019 using System.Collections;
00020 using System.Text;
00021
00022 namespace DXGfxLib
00023 {
00030 public class StringUtil
00031 {
00035 public StringUtil()
00036 {
00037 }
00038
00045 public static string GetExtension(string fileName)
00046 {
00047
00048
00049
00050 if (fileName != null)
00051 {
00052 int lind = fileName.LastIndexOf(".");
00053 if (lind != -1)
00054 {
00055 return fileName.Remove(0, lind);
00056 }
00057 else
00058 {
00059
00060
00061 return "";
00062 }
00063 }
00064 return null;
00065 }
00066
00073 public static string GetName(string fileName)
00074 {
00075 if (fileName != null)
00076 {
00077 int lind = fileName.LastIndexOf("\\");
00078 if (lind != -1)
00079 {
00080 return fileName.Remove(0, lind + 1);
00081 }
00082 else
00083 {
00084
00085
00086 return fileName;
00087 }
00088 }
00089 return null;
00090 }
00091
00098 public static string GetRelativePath(string basePath, string fileName)
00099 {
00100 if ((fileName != null) && (basePath != null))
00101 {
00102 int lind = fileName.IndexOf(basePath);
00103 if (lind != -1)
00104 {
00105 return fileName.Remove(lind, basePath.Length);
00106 }
00107 else
00108 {
00109
00110
00111 return null;
00112 }
00113 }
00114 return null;
00115 }
00116
00123 public static string GetRelativePathWithoutStartingSlash(string basePath, string fileName)
00124 {
00125 if ((fileName != null) && (basePath != null))
00126 {
00127 int lind = fileName.IndexOf(basePath);
00128 if (lind != -1)
00129 {
00130 return fileName.Remove(lind, basePath.Length+1);
00131 }
00132 else
00133 {
00134
00135
00136 return null;
00137 }
00138 }
00139 return null;
00140 }
00141
00148 public static string GetPath(string fileName)
00149 {
00150 if (fileName != null)
00151 {
00152 int lind = fileName.LastIndexOf("\\");
00153 if (lind != -1)
00154 {
00155 return fileName.Remove(lind + 1, fileName.Length - (lind + 1));
00156 }
00157 else
00158 {
00159
00160 return null;
00161 }
00162 }
00163 return null;
00164 }
00165
00171 public static string GetPathWithoutTrailingSlash(string fileName)
00172 {
00173 if (fileName != null)
00174 {
00175 int lind = fileName.LastIndexOf("\\");
00176 if (lind != -1)
00177 {
00178 return fileName.Remove(lind, fileName.Length - (lind));
00179 }
00180 else
00181 {
00182
00183 return null;
00184 }
00185 }
00186 return null;
00187 }
00188
00194 public static string AppendDirectorySeparator(string path)
00195 {
00196 return (string)(path + "\\");
00197 }
00198
00205 public static string GetNewIndexedName(string name, Hashtable hash)
00206 {
00207 if (hash.Contains(name))
00208 {
00209 int index = 1;
00210 while (hash.Contains(name + index))
00211 index++;
00212
00213 return name + index;
00214 }
00215 else
00216 return name;
00217 }
00218 }
00219 }