The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
I am quite new to most of this and am having a little difficulty with the MicroFramework.
I am building a project to pull info off the web and display it - I am able to gather info and am able to parse info now, but the one bit I text that I gather is surrounded by white space.
I have found the NetMF 4.2 replace, but my string is returned with some line breaks and I am unsure how to remove line breaks from my string.
If anyone knows this off the top of your head, please fire it my way.
Hi folks,
I can't find String.Replace in my NetDuino Plus project. This is the error:
"String does not contain a defenition for 'Replace' and no extension method...bla bla bla"
I use .Net MF 4.1
Hi All,
When I use the function Replace(unwanted, replacement) of stringBuilder, if the "replacement" string length is bigger than "unwanted" length then the method throws "OutOfRangeException". I have microframework 4.2.
Thanks in advance.
Hi folks,
I can't find String.Replace in my NetDuino Plus project. This is the error:
"String does not contain a defenition for 'Replace' and no extension method...bla bla bla"
I use .Net MF 4.1
You cant actually do a <string>.Replace(), as strings don't have that method in the micro framework.
You can, however, do what bulletprooffool did and roll your own Replace() function, and call it wherever you need it. I like to have a utils.cs class to keep this kind of crap handy.
[OR]
If you don't want to get that fancy/reusable with it, you can just do it inline-ish by doing exactly what is in that function; make the String a StringBuilder, do your fiddling, and then assign it back to your original gangster String. That will look a little something like this:
String tacoString = "I like Tacos";
// "I like Tacos"
StringBuilder tacoStringBuilder = new StringBuilder(tacoString);
tacoString = tacoStringBuilder.Replace("like","love").ToString();
// "I love Tacos"
Just be sure you get that last .ToString() in there; I don't think it will compile if you don't.
Hi All,
When I use the function Replace(unwanted, replacement) of stringBuilder, if the "replacement" string length is bigger than "unwanted" length then the method throws "OutOfRangeException". I have microframework 4.2.
Thanks in advance.
I haven't had issues with the replacement text being longer than what it is replacing.
I found a pretty interesting bug back when 4.2 was still alpha-ish; outlined here
Have you tried with a shorter base string? You could possibly be running out of memory on the netduino. Try and compile a simple .NETMF project and run it locally on your PC. If it works there, but not on your netduino, I'm guessing you're asking a bit too much from it.
Possible workaround: Look at an example on the thread I linked above (first post in that thread, iirc) that reads through one char at a time and does the replacing that way. It was Valkyrie-MT's example. [WARNING: It's not pretty]
One other thought: .NET Micro Framework supports extension methods.
So you may be able to extend the String class in .NET Micro Framework and use your desktop .NET code as-is.
Chris
I'm trying to post a date/time via an HTTP request for an application I'm writing. The only problem is that I am getting an error because of the space in the date/time.
string = "&dateTimeStamp=06/01/2011 00:00:28"
I need it to be
string = "&dateTimeStamp=06/01/2011%2000:00:28"
I have created the following:
public static string replace(string str, string unwanted, string replacement)
{
StringBuilder sb = new StringBuilder(str);
sb.Replace(unwanted, replacement);
return sb.ToString();
}
but calling it like this does not get rid of the space:
I'm trying to post a date/time via an HTTP request for an application I'm writing. The only problem is that I am getting an error because of the space in the date/time.
I need it to be
I have created the following:
public static string replace(string str, string unwanted, string replacement)
{
StringBuilder sb = new StringBuilder(str);
sb.Replace(unwanted, replacement);
return sb.ToString();
}
but calling it like this does not get rid of the space:
Is there an escape character I should use for replacing the space?
Thanks,
Donovan
What version of the framework and firmware are you using. I tried this using 4.2.0.1 and it replaced the space however it messed up the time. If my time was "11/26/2012 00:00:00" after the replace it showed as "/211/26/201%2000:00:00". Probably a bug in the framework.
I came across a codeplex project called .NET Micro Framework - Common Extensions that adds a few helpful extension methods, including string.replace. I have used a few of them, and have not had any issues with using them on NetMF 4.2. Hopefully it is as helpful for you as it was for me.