- Home /
Question by
lancer · Aug 21, 2013 at 04:46 PM ·
javascriptstrings
Remove string value with substring
My function downloads a table as a string and I need to remove a part of it. here is the first part:
{"Footer":"<tfoot><tr><td colspan=\"6\"><strong>Last Update: <\/strong> August 21, 2013 at 10:24 <strong>Next Update: <\/strong> August 21, 2013 at 10:29<\/td><\/tr>\u000d\u000a<\/tfoot>\u000d\u000a","RowData":"[['Wednesday, August 21, 2013','11:20',
And I'm trying to remove:
{"Footer":"<tfoot><tr><td colspan=\"6\"><strong>Last Update: <\/strong> August 21, 2013 at 10:24 <strong>Next Update: <\/strong> August 21, 2013 at 10:29<\/td><\/tr>\u000d\u000a<\/tfoot>\u000d\u000a","RowData":"[
I'm using:
var data : String = www.text;
var n = data.IndexOf("\":\"[");
Debug.Log(n);
data.Remove(n);
Debug.Log(data);
But when the log prints data it still has the substringed part. Why is substring not removing the part specified from the string?
Comment
var n = data.IndexOf('":"['); should be var n = data.IndexOf("\\":\\"[");
Are you trying to remove that string from line 2 from data?
Best Answer
Answer by lancer · Aug 21, 2013 at 06:08 PM
var data : String = www.text;
var n = data.IndexOf("\":\"[");
Debug.Log(n);
var y = data.Substring(0,n);
Debug.Log("Substring " + y);
data = data.Remove(0,n+4);
Debug.Log(data);
Answer by DaveA · Aug 21, 2013 at 05:43 PM
data = data.Substring(n); // or something like this
http://msdn.microsoft.com/en-us/library/system.string.substring.aspx
I tried that but then all data was was, the part I wanted removed.