A urine screen will generally show positive 48 to 72 hours after a single use of cocaine.
The longest I've heard of is 9 days and that was for two different individuals who smoked crack daily for months before the use-stopping/testing-start date, with the last 2 weeks being non-stop use.
I don't know much about hair testing, but found the below at www.drugtestingnetwork.com/hair-testing.htm
"Hair testing generally uses 1-1/2 inches of hair, representing about 3 months’ growth (head hair normally grows at about 1/2 inch per month). It is generally accepted that in order to test positive, the drug in question must have been used 3 times or more within the window of the test. After a drug is used, it takes about 7-10 days for the hair containing the drug to grow out of the scalp enough to be cut. Therefore, the hair test will not include drugs used in the week prior to the test. The drug remains in the hair, growing out much the same as hair dye and "dark roots". Eventually that hair containing the drug is cut off with normal haircuts."
Coke stays in your system up to 3 weeks if you're a chronic user. Hair tests go back 30 days per .5 inch of hair. Most tests use 1.5 inches, so that's 90 days. The best way to avoid detection is to stop using. This is some heavy stuff and shouldn't be played around with.