This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / a small VB questionI have a phone number like (416)123-45-67*007,
I want to reaplce the second hyphen with a NULL string("")
(because it's a obvious mistake in a telephone number),
what would you do to solve the problem?
(hint: you can not use the real number like 45,67 as
your search symbol, because I have a lot of different
numbers like this, I need a general solution)
dim sVariable as string
sVariable = "(416)123-45-67*007"
then......?
-interview(intervieweree);
2002-2-12
{444}
(#366490@0)
-
use substring() to find the second hyphen, then remove it. so (416)123-45-67 will become to (416)123-4567, that's what you want, right?
-luoboyang(萝卜秧);
2002-2-12
(#366551@0)
-
em.....,. it's not I'm looking forthe actulal situation is:
I got phone number looks like 416-123-45-67-789,
I want to remove the second and third hyphens
and replace the last one with "ext".
sometimes the string comes up as 416-123-4567-789
which is almost correct, just needs to replace last
one with "ext" and replace the second "-" with "",
any general solutions?
and what about situations 416-12345-67-789?
I remember I saw very short piece of code to address this.
can not remember now.....
-interview(intervieweree);
2002-2-12
{490}
(#366588@0)
-
a dumb wayremove all hyphens
check string length
if length < 10
error
else if length=10
make it 416-123-4567
else if length >10
make it 416-123-4567 ext 8999
-hellangel(地狱天使);
2002-2-12
{172}
(#366608@0)
-
too dumb to...........
-interview(intervieweree);
2002-2-12
(#366639@0)
-
tryremove all hyphens and non-numeric characters.
then add two hyphens after the thrid number and sixth number.
add "Ext " after 12th(10 digital and 2 hyphens) character.
I think it should work for 10 digital phone numbers.
-goodbaby(小宝);
2002-2-12
{225}
(#366613@0)
-
and let this function run on client, fired when client try to write DB
-gugu(GuGu);
2002-2-12
(#366621@0)
-
a smart idea, but.....we have to deal with variable length digit between first dash and last one,
here is an extreme example(normally is between 5 to 8 digits):
1-416-81-2878-3-4-5999-6-7.....8-9-9-789
the rule is:
before the second dash, it's area code,
and area code itself varies, for instance,
(US--1,UK---->44, HK--->512?)
after the last dash, it's extention number.
how to do?
-interview(intervieweree);
2002-2-12
{376}
(#366636@0)
-
first at all, you have to clearly know what client will input and what client have to input (client side restrict), where and how to store these data (server side data structure),if your data structure is normalized, you will not have that kind of mess.
-gugu(GuGu);
2002-2-12
{74}
(#366657@0)
-
right, make a rule 先。可以用input mark来做一些限制。还是你说你的数据已经是这样的mess了?
-luoboyang(萝卜秧);
2002-2-12
(#366666@0)
-
It's even worse....the real data is like
1-416-123*-887-*9877@888-99908
one thing I'm sure is before 416 is area code and after the final
dash, it's extention.
it's transfered from a legacy system and I got only
a txt file contians all these numbers.
any solutions?
-interview(intervieweree);
2002-2-12
{263}
(#366726@0)
-
记得几年前用过QE(QUICKEDIT)有列编辑功能, 对于这种文本特有用,然后BCP.没看到你的格式,没发给意见
-gugu(GuGu);
2002-2-12
(#366740@0)
-
kidding me?It's transfered from a database, Megabytes level,
any editor can deal with that?
the typical formats are
1) 1-416-512*187-0-999--->should be (1)416-5121780ext999
2) 44-321-1&85-888---->should be (44)321-185ext888
3) 1-416-6658790-8879--->should be (1)416-6658790ext8879
all non-nummeric characters in the middle should removed
-interview(intervieweree);
2002-2-12
{339}
(#366757@0)
-
use Replace() function, refer to MSDN
-nym(沙鸥);
2002-2-12
(#366780@0)
-
I tried before, no use...........
-interview(intervieweree);
2002-2-12
(#366801@0)
-
mayget the data part before first dash, delete Non-numeric, you got (1)
get the data after the last dash, delete non-numeric, you got ext99908
get the middle part
get the data part before first dash, delete Non-numeric, you got 416-
delele Non-numeric among the data after dash, you got 123887
-gugu(GuGu);
2002-2-12
{295}
(#366803@0)
-
logic clear, but....but imagine how may instr(), mid() you will use
and you definitely need a loop, it's not clear.
The solution I saw before is just about 5 to 6 lines
no loop.
-interview(intervieweree);
2002-2-12
{162}
(#366819@0)
-
I 服了U. Spending 5 hours waiting/searching for a 5-6 lines solution, but do not want to write 20 lines of codes.
-hellangel(地狱天使);
2002-2-12
(#366836@0)
-
如果你可以肯定要找的是“-”的话,可以用instr()找出两个“-”的位置,然后用substr()把原来的string分成3段,把中间的那段处理成全部是数字的string,然后再接起来。
-fionah(Fiona);
2002-2-12
(#366815@0)
-
look at my post above
-interview(intervieweree);
2002-2-12
(#366826@0)
-
你会用instr()吗?instr()返回该字符在String中的位置。我就是看了你的post才说用instr()的,否则hellangel(地狱天使)的方法最简单。
-fionah(Fiona);
2002-2-12
(#366842@0)
-
他只是要5-6 行CODE
-gugu(GuGu);
2002-2-12
(#366851@0)
-
sed & awk (or Perl) should be the best tools for this kind of task. But it's unix centric and has a bit of learning curve.
-dennis2(Dennis);
2002-2-12
(#366853@0)
-
Hope it's helpfulsNumber = Split(sVariable, "-")
If UBound(sNumber) > 1 Then
sVariable = sNumber(0) & "-"
For i = 1 To UBound(sNumber)
sVariable = sVariable & sNumber(i)
Next
End If
-ion(ion);
2002-2-12
{220}
(#366852@0)
-
you have to be assuming that all the phone numbers are valid, then simply remove all the non-numeric charactors first, then reformat it based on the length of the remains, say, 10=3-7;13=3-7ext3; 11=1-800-7 etc. and so on
-rootbear(啤酒晕头);
2002-2-12
{37}
(#366919@0)