Hi Thorsten,
You could try using a regular expression:
Match match = Regex.Match(input, "[\+\-](?<N>\d*\(\.\d+)?)(?<S>\w+)");
if (!match.Success)
throw new FormatException("Invalid input data.");
float number = float.Parse(match.Groups["N"].Value);
string scale = match.Groups["S"].Value;
(I didn't test this code so it might need some mods.)
Regular Expression Language Elements
http://msdn2.microsoft.com/en-us/library/az24scfc.aspx
--
Dave Sexton
"Thorsten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi everyone,
>
> I am rather new to C# and have a problem that will probably seem trivial
> to most of you... but I hope you can still help me nevertheless..
>
> Via the comport, I read the result of a digital scale... the result is
> sent as a string like "+0000.23kg", representing the weight in kilograms.
>
> In order to work with the returned value, I need to use it as a float or
> decimal or double... I tried casting it via Convert, via float.Parse
> etc... but I always get either a wrong value (eg. "0000.24" results in
> "24" instead of "0.24") or an exeption.
>
> Does anyone have an Idea how I can get this as a float?
>
> Thanks!
>
> Thorsten
>