Formatted string in .Net Micro


I am rather new still to C# and .Net Micro

I want to format a string similar to a sprint in C/C++

ie. sprint(buffer,“Temperature: %3.2f”, temp)
any suggestions for where to read or examples are appreciated.


hi Sandra, and welcome.

you need to look at ToString and it’s formatting capabilities. Here’s the standard .Net information (nice and detailed) but the NetMF implementation is somewhat reduced, you may have to look at other options like the CommonExtensions work

@ smgvbest - The equivalent of sprintf in C# is String.Format(format, variables…). But this is not available in the Micro Framework.

Thank you Brett and Mike

Both answers helped understand and find a solution

Doing this

Debug.Print("Temperature: " + currentTemperture.ToString(“N2”) + " Relative Humidity: " + currentHumidity.ToString(“N2”));

displayed what I needed. before the display I had to convert the temp from Celsius to Fahrenheit
but now I am seeing what I want to see in the output

I’m enjoying this and have a project I’m working towards but allot to learn


1 Like