我使用文件上传和服务器上保存的照片上传照片,我也在数据库中保存了图像路径。我想使用数据库中的路径检索将图像绑定到图像控件。 以下是检索的路径。 D:\ TFS \User \ Tech.Apps.Ever.Web \ Tech.Apps.Ever.Web \ Doctor \ DOCUMENTS\1326 \照片\ Pengengins.jpg i想删除一个字符串D:\ TFS \User\Tech.Apps.Ever.Web \ Tech。 Apps.Ever.Web \ 之后我想使用剩余路径绑定图像,即Doctor \DOCUMENTS \1326 \Photograph\Penguins。 JPG。请帮我解决我的问题。 谢谢 Manohar
解决方案string test = @ D:\ TFS \ User.Tech.Apps.Ever.Web \ Tech.Apps.Ever.Web \ Doctor \ DOCUMENTS\1326 \ Photograph \ Penguins.jpg; int index = test.IndexOf( 医生); string sub = test.Substring(index,test.Length - index); MessageBox.Show(sub);
那个 string notSoLongPath = givenPath.SubString(( @ D:\ TFS \ User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\)。长度);
它使用子串 [ ^ ]提取字符串一部分的方法。要知道哪个部分, String.Length [ ^ ]属性可以传递给定字符串的长度,在这种情况下是硬编码的字符串文字。 请记住,一般来说,对任何路径进行硬编码都不是一个好主意。相反,将路径存储在应用程序的资源中。
您好, 试试这个 string s = @ d:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg; s = s.Replace( @ D:\ TFS \ User.\\ Tech.Apps.Ever .Web\Tech.Apps.Ever.Web \, ) ;
希望有所帮助。
I am upload photograph using file upload and saved photo in server and i also saved image path in database. i want to bind image to image control using path retrieve from database. following is the path which is retrieve. "D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg" i want to remove a string "D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\" after that i want to bind image using remaining path i.e. "Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg". please help me to solve my isssue. Thanks Manohar
解决方案 string test=@"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg"; int index=test.IndexOf("Doctor"); string sub = test.Substring(index, test.Length - index); MessageBox.Show(sub);How about that onestring notSoLongPath = givenPath.SubString( (@"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\").Length );It uses the Substring[^] method to extract a portion of a string. To know what portion, the String.Length[^] property can deliver the length of a given string, in this case of a hard-coded string literal. Remember that in general, hard-coding any paths is not a good idea. Instead, store the path in your application's resources.
Hi, Try this string s = @"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\Doctor\DOCUMENTS\1326\Photograph\Penguins.jpg"; s = s.Replace(@"D:\TFS\User\Tech.Apps.Ever.Web\Tech.Apps.Ever.Web\", "");Hope it helps.
更多推荐
如何删除特定点的字符
发布评论