Re: Create String from char - so difficult??



Roedy Green wrote:
On Sat, 22 Mar 2008 03:57:04 -0700 (PDT), column.column@xxxxxxxxx
wrote, quoted or indirectly quoted someone who said :

How to create new String having one char. Is it really only way to
create new char array that has length one and using it create string?

Surely somebody has had it up to here with the irregularity of Java
conversion functions and written a wrapper class to convert any
primitive to any other (plus strings).

like this

double Cvt.todouble( String s );
float Cvt.tofloat ( int i );
Float Cvt.toFloat ( long l );

I understand why you did it, but the lack of camel case is jarring (no pun intended). Besides, with autoboxing you don't need two versions:

float f = Cvt.toFloat( int i );
Float fc = Cvt.toFloat( int i );

Then again,

float f = i;

works just fine.

As for String conversions, I don't understand what you mean by the "irregularity" at all. The String class has valueOf() overloads for all the primitive types. The primitive type wrapper classes except Character have valueOf( String ) overloads. It's hard to be more regular than that, unless you insist on "remedying" the sole exception of Character, and I suspect that one is due to the special relationship between Strings and chars and the existence of String.charAt().

It's not worth running around Jericho's barn to wind up where I'm already standing.

--
Lew
.



Relevant Pages

  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... to strcmpwhich expects a pointer to a string. ... And now a question about something else: why do you use floating ... int,float, char, etc. ...
    (comp.lang.c)
  • Re: inconsistent behavior of >FLOAT
    ... empty string, strings with leading and trailing blanks. ... I think it is too late for>FLOAT to rescind the strong suggestion in its spec that this "should" be the case. ... As long as the spec is tightened to require that a string of blanks must be treated as a valid zero, a programmer would know to filter such a case, if needed, before it is passed to>FLOAT. ... I think ignoring leading and trailing blanks may be reasonable for>FLOAT, as long as it does not violate the current spec. ...
    (comp.lang.forth)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... And now a question about something else: why do you use floating ... use then to copy a float into a char *1. ... binary representation doesn't resemble a string like "123.46343" ...
    (comp.lang.c)
  • Re: How to marshall "pointer to pointer"
    ... UInt16 Layer, ByteInstanceName, float X, float Y, BytePath, IntPtr ... DstPath); ... IntPtr and pass it it Marshal.PtrToStringBSTR() to get this string. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: help with Table Macro
    ... Available Float, which will always be in column ... string contained in that cell. ... test phrase "available float". ... next matching word and repeat the process until no more matching words ...
    (microsoft.public.word.application.errors)