Im trying to excersize on substring but its not working good
the code is:
private void test() { int countfiles = 0; byte[] a; string starttag = "t256=\""; string endtag = "\""; int starttagwidth = starttag.length; int endtagwidth = endtag.length; index = 0; w = new streamwriter(@"c:\test.txt"); while (true) { index = f.indexof(starttag, index); string test = f.substring(index , starttagwidth); if (index == -1) { break; }
the starttag t256= endtag should 1 qouta "
i need find between t256 , "
for example if have t256="hi mose" need hi mose
for im getting t256=
what should next ? ( substring testing far not need in final result )
danieli
hi danieli,
i found old code in library. it working fair requirement.
private void form1_load(object sender, eventargs e) { string data = "t256=\"hi mose\""; string starttag = "t256=\""; string endtag = "\""; string result = getstringbetween(data, starttag, endtag); } public string getstringbetween(string data, string startkey, string endkey) { if (string.isnullorempty(data) || string.isnullorempty(startkey) || string.isnullorempty(endkey)) return string.empty; if (!data.contains(startkey) || !data.contains(endkey)) return string.empty; int ix_start = data.indexof(startkey); int ix_end = data.indexof(endkey, ix_start + startkey.length); int valuestart = ix_start + startkey.length; string ret = data.substring(valuestart, ix_end - ix_start - startkey.length); return ret; }
please try it.
resolving n evolving in c# (http://jeanpaulva.com)
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment