🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #698

Re: Color to Hex string

#698
From: Alan Shiers
Date: Wed, 01 Dec 2004 13:30
22 lines
1609 bytes
> I do not know of one that exists already, but it is not very hard to write
> one:
>
> public String convertColorToHexString(java.awt.Color c)
> {
>    String str = Integer.toHexString( c.getRGB() & 0xFFFFFF );
>    return ( "#" + "000000".substring( str.length() ) +
str.toUpperCase() );
> }

Wow.  That's all I really needed.

Just curious about one thing though, John.  On the second line you write:

"000000".substring( str.length() )

Why is this necessary?  I wrote out a println statement:
System.out.println("substring = " + "000000".substring( str.length() ));
And all this does is return an empty string.  Why concatonate with an empty
string? Is there some reason for this?

Alan
Technical Details
Message-ID: <41adc82f$3@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41acd295$1@newsgroups.borland.com> <xn0dqhf5t1hnd2f006@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,77c23dd879f84904
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Alan Shiers" <ashiers@hfx.eastlink.ca>
Newsgroups: borland.public.jbuilder.java.language
References: <41acd295$1@newsgroups.borland.com> <xn0dqhf5t1hnd2f006@newsgroups.borland.com>
Subject: Re: Color to Hex string
Date: Wed, 1 Dec 2004 09:30:12 -0400
Lines: 24
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 24.222.101.2
Message-ID: <41adc82f$3@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101908015 24.222.101.2 (1 Dec 2004 05:33:35 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail