PC Review


Reply
Thread Tools Rate Thread

Replacing a character in a string with another character

 
 
=?Utf-8?B?Y2hlcm1hbg==?=
Guest
Posts: n/a
 
      2nd Aug 2007
I need to replace the 1st "." in
"(E-Mail Removed)" with "_". Or I need to remove
it completely. This is a filename that I need to import, but this period is
causing the import to error out.

Actually I am writing a proc that will cycle through the .csv files in a
folder and I need to make the above replacement for all .csv files that start
with "PartnerContract". Below is the code I have so far. Any suggestions as
to how I can complete this would be greatly appreciated.

'Set file type.

strFile = Dir$(PathName & "*.csv*")

'Check if any .csv files are in Imports directory.

If Len(strFile) > 0 = False Then
MsgBox "There are no update files.", vbOKOnly, "WARNING"
Exit Sub
End If

'Import all .csv files in Imports directory.

Do While Len(strFile) > 0

If Left(strFile, 15) = "PartnerContract" Then

strFile = Dir$()

End If

Loop
 
Reply With Quote
 
 
 
 
missinglinq via AccessMonster.com
Guest
Posts: n/a
 
      2nd Aug 2007
To replace the the 1st "." with an "_" use this, where OriginalFileName is
what you start with and NewFileName is what you end up with:

Private Sub OriginalFileName_BeforeUpdate(Cancel As Integer)
Dim I As Integer
Dim BeforeFirstDot As String
Dim AfterFirstDot As String

BeforeFirstDot = Left(Me.OriginalFileName, (InStr(OriginalFileName, ".") - 1))

AfterFirstDot = Right(Me.OriginalFileName, Len(Me.OriginalFileName) - (InStr
(OriginalFileName, ".")))

NewFileName = BeforeFirstDot & "_" & AfterFirstDot

End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...dules/200708/1

 
Reply With Quote
 
Ken Snell \(MVP\)
Guest
Posts: n/a
 
      2nd Aug 2007
You can use the Replace function to change just the first occurence of "."
to "_":

ModifiedName = Replace(OriginalFileName, ".", "_", 1, 1, 1)

To rename all .csv files in a folder, this code snippet should work:

Dim strFileOrig As String, strPathName As String, strFileNew As String
strPathName = "YourPathString\"
strFileOrig = Dir(strPathName & "*.csv")
Do While strFileOrig <> ""
strFileNew = Replace(strPathName & strFileOrig, ".", "_", 1, 1, 1)
Name strPathName & strFileOrig As strPathName & strFileNew
strFileOrig = Dir()
Loop


--

Ken Snell
<MS ACCESS MVP>


"cherman" <(E-Mail Removed)> wrote in message
news735B943-FBC9-4F86-867C-(E-Mail Removed)...
>I need to replace the 1st "." in
> "(E-Mail Removed)" with "_". Or I need to
> remove
> it completely. This is a filename that I need to import, but this period
> is
> causing the import to error out.
>
> Actually I am writing a proc that will cycle through the .csv files in a
> folder and I need to make the above replacement for all .csv files that
> start
> with "PartnerContract". Below is the code I have so far. Any suggestions
> as
> to how I can complete this would be greatly appreciated.
>
> 'Set file type.
>
> strFile = Dir$(PathName & "*.csv*")
>
> 'Check if any .csv files are in Imports directory.
>
> If Len(strFile) > 0 = False Then
> MsgBox "There are no update files.", vbOKOnly, "WARNING"
> Exit Sub
> End If
>
> 'Import all .csv files in Imports directory.
>
> Do While Len(strFile) > 0
>
> If Left(strFile, 15) = "PartnerContract" Then
>
> strFile = Dir$()
>
> End If
>
> Loop



 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      2nd Aug 2007
On Thu, 2 Aug 2007 10:58:01 -0700, cherman wrote:

> I need to replace the 1st "." in
> "(E-Mail Removed)" with "_". Or I need to remove
> it completely. This is a filename that I need to import, but this period is
> causing the import to error out.
>
> Actually I am writing a proc that will cycle through the .csv files in a
> folder and I need to make the above replacement for all .csv files that start
> with "PartnerContract". Below is the code I have so far. Any suggestions as
> to how I can complete this would be greatly appreciated.
>
> 'Set file type.
>
> strFile = Dir$(PathName & "*.csv*")
>
> 'Check if any .csv files are in Imports directory.
>
> If Len(strFile) > 0 = False Then
> MsgBox "There are no update files.", vbOKOnly, "WARNING"
> Exit Sub
> End If
>
> 'Import all .csv files in Imports directory.
>
> Do While Len(strFile) > 0
>
> If Left(strFile, 15) = "PartnerContract" Then
>
> strFile = Dir$()
>
> End If
>
> Loop


Only the first dot?

If your version of Access includes the Replace function .....

Dim strString as String
strString = "Whatever"

If Left(strString,15) = "PartnerContract" then
Replace(strString, ".", "_", ,1)
End If

will return:
PartnerContract_clintonherman@yahoo_com.csv


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
replacing a string that contains a " character Milsnips Microsoft C# .NET 4 17th May 2007 06:19 PM
Replacing string character John Microsoft VB .NET 3 10th Jul 2006 10:11 PM
replacing a character in a string Craig Microsoft Access VBA Modules 1 25th May 2004 06:22 PM
Replacing a Character in a String C# Learner Microsoft C# .NET 4 22nd Jan 2004 10:52 AM
Replacing newline character in a string chrisy H Microsoft Outlook Form Programming 1 16th Jul 2003 08:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 AM.