Replace function for specific postion

chris-uk-lad

Registered User.
Local time
Today, 12:00
Joined
Jul 8, 2008
Messages
271
Hi all,

Currently need to fine a way to change my file:
123-1-Cornwall

I want to remove the -1 character from the above file to leave:
123 - Cornwall

Ive been looking at things an believe replace is what i need but not sure how to adapt it to the 2 character positions.

Code:
currentFile = Replace(currentFile, 5, "")

All help appreciated, i know the mid function can return the 2 characters i want, but not remove them.
 
stuff like this is never easy

if you have a fixed format, so the stuff you want to remoive is always in the same position, its straight forward

if you always have the format

number dash number dash text then its easier

find the position of the first dash
find the positon of the second dash

then new string = left(position of first dash) & mid(one after second dash, to the end)

-------
if you dont always have two dashes then its a bit more awkward.

---------
to analyses the string,
you need to use either instr function to search the string, or possibly easier split function, to split the string based on dash charcters

then reassemble the string
 
thanks gemma, it relates to my previous post so only files with a start of number-number-text will be included in a if statement that works this out so will always be true
 
If your always going to have 2 dashes then you coudl try something like:

Code:
dim strArray() as variant
dim strName as string

strName = "123-1-Cornwall"

strArray = split(strName, "-")

strname = strAray(1) & " - "  & strArray(3)
 
If your always going to have 2 dashes then you coudl try something like:

Code:
strArray = split(strName, "-")

I receive a type mismatch on this :x (though im passing in the currentFile, which holds the strName
 
Two points

It should be

Dim strArray() as String

and arrays in Access start at 0

so

should be

strname = strArray(0) & " - " & strArray(2)
 

Users who are viewing this thread

Back
Top Bottom