0

why wont this work, I am trying to format the phone as a standard

Dim Patient = From line In System.IO.File.ReadAllLines("K:\PAT02.txt")
Select New With { _
Key .PatientID = line.substring(0,7).trim, _
.FirstName = line.substring(7,11).trim, _
.MiddleName = line.substring(18,1).trim, _
.LastName = line.substring(19,15).trim, _
.Home = (String.Format("{0:(###)###-####}", line.substring(112,10).trim)), _        
} 
Hiro Yoshida
  • 23
  • 1
  • 4
  • 2
    What's the problem? Error message? Exception? – Daniel Hilgarth Sep 24 '12 at 15:11
  • Possible duplicate of this: http://stackoverflow.com/questions/188510/how-to-format-a-string-as-a-telephone-number-in-c-sharp the title here is mentioning Linq but actually Linq is not involved at all in the mentioned problem – Wasp Sep 24 '12 at 15:33

1 Answers1

0

You have an extra comma at the end of your New With block, remove it and your code will compile.

About your phone number problem, you're using number formatting, so you must pass a number to the String.Format method:

.Home = String.Format("{0:(###)###-####}", CLng(line.substring(112,10).trim))
Meta-Knight
  • 17,626
  • 1
  • 48
  • 58
  • Done and that does not work, that expression is actually the cut down version that line .Home = (String.Format("{0:(###)###-####}", line.substring(112,10).trim)) _ inly returns the contents of line.substring(112,10).trim)) – Hiro Yoshida Sep 24 '12 at 20:21
  • I just wrote a separate function and it seems to have done the job – Hiro Yoshida Sep 24 '12 at 21:17