Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Reformat a phone number that is a string
Old 12-08-2006, 01:29 PM Reformat a phone number that is a string
Junior Talker

Posts: 2
Name: DP
Trades: 0
Hello, I’m new to this forum; I’m needing help on how to reformat a phone number which is being read in as a string. It’s being read from a text file in the format of 222/222-2222. I’m needing to write the phone number in the format of 2222222222 to another text file. I’ve tried the ToString, it didn’t work, I’ve tried String.Reformat, that doesn’t work. I have all the code I need to be able to read and write to the text files, but phone number I’m struggling with to reformat it. Does anyone have any know how I can do this? I would appreciate the help thanks. I’ve attached my code from where I declare my variables to where I write out the new text file, just so everyone understands what I’m trying to do. Thanks.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Visible = True
Dim slnin As String = ""
Dim slnout As String = ""
Dim outputfile As String = ""
Dim semi As String = ""
Dim national_id As String = ""
Dim last_name As String = ""
Dim first_name As String = ""
Dim mid_initial As String = ""
Dim suffix As String = ""
Dim dept_ID As String = ""
'Dim payroll As String = ""
Dim address1 As String = ""
Dim address2 As String = ""
Dim city As String = ""
Dim state As String = ""

Dim postal As String = ""
Dim phone As String

Dim hire_dt As New Date()
Dim mystring As String = hire_dt.ToString("MM/dd/yyyy")
Dim reg_temp As String = ""
Dim full_part_time As String = ""
'Dim hire_dt As String = ""
Dim appt_type As String = ""
Dim barg_unit As String = ""
Dim oh_bu_flag As String = ""
Dim jobcode As String = ""
Dim business_title As String = "" ' coded this variable thinking this was the job_title
Dim termination_dt As String = "" ' coded this variable thinking this was the separation_dt
Dim action As String = ""
Dim action_reason As String = ""
Dim pay_period_end As New Date()
Dim paystring As String = pay_period_end.ToString("MM/dd/yyyy")
Dim emp_id As String = ""
Dim empl_rcd As String = ""
Dim class_indc As String = "" ' code this variable thinking this was the job_indicator



'Dim mystringbuilder As New StringBuilder
semi = ";"

If FileUpload1.HasFile Then

'upload file
'Dim filein As String = FileUpload1.HasFile
'Dim objstreamreader As StreamReader
'

'declaring variables

'Dim orig_hire_dte As String = ""
'im filename As String
'Dim objstreamreader As StreamReader
Dim filename As String = ""
If filename = String.Empty Then
filename = FileUpload1.PostedFile.FileName
End If
Dim sr As StreamReader
'Dim streamreader As New StreamReader("c:\mastertestfile.txt")
sr = File.OpenText(filename)

While sr.Peek() <> -1
slnin = sr.ReadLine

'slnin = objstreamreader.ReadLine
'Do While Not strline Is Nothing

'objstreamreader = File.OpenText(filename) 'may undo
'objstreamreader = File.OpenText()'may undo


If Not slnin Is Nothing Then 'store text in slnin

national_id = slnin.Substring(1384, 20)
last_name = slnin.Substring(1650, 30)
first_name = slnin.Substring(1685, 30)
mid_initial = slnin.Substring(1720, 30)
suffix = slnin.Substring(1645, 15)
dept_ID = slnin.Substring(0, 9)
address1 = slnin.Substring(391, 54)
address2 = slnin.Substring(446, 55)
city = slnin.Substring(501, 30)
state = slnin.Substring(531, 6)
postal = slnin.Substring(537, 12)
phone = slnin.Substring(549, 24)
If IsDate(slnin.Substring(341, 10)) = False Then
hire_dt = "01/01/1900"
Else
hire_dt = slnin.Substring(341, 10)
End If
reg_temp = slnin.Substring(52, 1)
full_part_time = slnin.Substring(152, 1)
appt_type = slnin.Substring(5161, 1)
barg_unit = slnin.Substring(317, 4)
oh_bu_flag = slnin.Substring(316, 1)
jobcode = slnin.Substring(27, 6)
business_title = slnin.Substring(33, 10) ' this did not match up with the layout(job title)
termination_dt = slnin.Substring(361, 10) ' this did not match i thought this was separation date
action = slnin.Substring(68, 3)
action_reason = slnin.Substring(71, 3)
If IsDate(slnin.Substring(1800, 10)) = False Then
pay_period_end = "01/01/1900"
Else
pay_period_end = slnin.Substring(1800, 10)
End If
emp_id = slnin.Substring(10, 11)
empl_rcd = slnin.Substring(21, 3)
class_indc = slnin.Substring(5163, 1) ' this did not match up with the layout(job indicator)


'last_name = last_name.PadRight(25)
'build line to be wrote out
'Dim myStringBuilder As New StringBuilder
'myStringBuilder.Append(national_id + semi)
slnout = national_id + semi
slnout += last_name.Trim.PadRight(30, " ") + semi
slnout += mid_initial + semi
slnout += first_name.Trim.PadRight(30, " ") + semi
slnout += suffix.PadRight(15, " ") + semi
slnout += dept_ID.PadRight(10, " ") + semi
slnout += address1.PadRight(55, " ") + semi
slnout += address2.PadRight(55, " ") + semi
slnout += city.PadRight(30, " ") + semi
slnout += state.PadRight(6, " ") + semi
slnout += postal + semi
slnout += phone + semi
slnout += hire_dt.ToString("MM/dd/yyyy") + semi
slnout += reg_temp + semi
slnout += full_part_time + semi
slnout += appt_type + semi
slnout += barg_unit + semi
slnout += oh_bu_flag + semi
slnout += jobcode + semi
slnout += business_title + semi
slnout += termination_dt + semi
slnout += action + semi
slnout += action_reason + semi
slnout += pay_period_end.ToString("MM/dd/yyyy") + semi
slnout += emp_id + semi
slnout += empl_rcd + semi
slnout += class_indc + semi & vbCrLf

outputfile += slnout
'Response.Write(slnout)
'Response.End()
End If
End While
'Response.Write(slnout)
'Response.End()
sr.Close()
__________________
Peebman2000
Beginner Programmer
peebman2000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-08-2006, 02:50 PM Re: Reformat a phone number that is a string
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Simple. Use a replace function
Code:
function FormatPhoneNumber(PhoneNumber)

 PhoneNumber= replace(PhoneNumber,"/","")
 FormatPhoneNumber= replace(PhoneNumber,"-","")
end function
useage
Code:
PhoneNumber = FormatPhoneNumber(PhoneNumber)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-08-2006, 03:12 PM Re: Reformat a phone number that is a string
Junior Talker

Posts: 2
Name: DP
Trades: 0
Hey thanks that worked. I appreciate the help.
__________________
Peebman2000
Beginner Programmer
peebman2000 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Reformat a phone number that is a string
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31766 seconds with 12 queries