拆分textarea给出了不正确的长度问题 [英] split textarea gives problem of incorrect lengt
问题描述
当我将textarea字符串拆分为数组时,问题是
下一行显示长度,再加上第二个数组数据中的一个,再加上i
使用过修剪仍未显示正确的长度,我已在textarea中输入数据为
关注
9021632082
9762471857
9888888888
8888888888
问题是第一个数组索引显示的长度为10
数组索引的其余部分显示数据长度11,这是错误的
但是数据只有10位数字,那么不知道
请帮忙
这是我的代码下面的
when i split textarea string into array the problem is that
next line is showing length plus one from second array data plus one though i
have used trim still not showing proper length i have entered data in textarea as
follows
9021632082
9762471857
9888888888
8888888888
problem is that first array index shows length 10
and rest of the array index shows data length 11 which is wrong
but data is of only 10 digits then no idea
please help
here is below my code
<!--#include file="common.asp"-->
<!--#include file="adminheader.asp"-->
<%
response.Expires=-1
flag=request.Form("flag")
if flag=1 then
OpenDataBase_macd conn
tostore=""
cantstore=""
alreadystore=""
invalidmobilenumbers=""
mobilenumber=trim(request.Form("mobilenumber"))
if mobilenumber="" then er=er & "<br><font color='red' size=2><center>Please Type Numeric Mobile Number</center></font><br>"
if er="" then
mobilenumberarray=split(mobilenumber,vbCr)
'response.Write ubound(mobilenumberarray) & "<br>"
for i=0 to ubound(mobilenumberarray)
if isnumeric(trim(mobilenumberarray(i))) then
'commented by rajiv
if(len(trim(mobilenumberarray(i)))=>10) then
set rs=server.CreateObject("adodb.recordset")
'mobilenumberarray(i)=right(mobilenumberarray(i),10)
rs.open "select mobilenumber from leads where mobilenumber='91"&mobilenumberarray(i)&"'",conn,1,1
if rs.recordcount=0 then
if tostore="" then
tostore="91"&mobilenumberarray(i)
sql="('91"& mobilenumberarray(i)&"',now()),"
else
sql=sql & "('91"&mobilenumberarray(i)&"',now()),"
tostore=tostore & ",91" & mobilenumberarray(i)
end if 'tostore
else
if alreadystore="" then
alreadystore=mobilenumberarray(i)
else
alreadystore=alreadystore & "," & mobilenumberarray(i)
end if 'cantstore
end if 'rs.recordcount
'conn.execute "insert into leads(mobilenumber,dtime) values('91"& mobilenumberarray(i) &"', now() ) "
rs.close
set rs=nothing
else
if invalidmobilenumbers="" then
invalidmobilenumbers=mobilenumberarray(i)
else
invalidmobilenumbers=invalidmobilenumbers & "," & mobilenumberarray(i)
end if 'invalidmobilenumbers
end if 'len
else
if invalidmobilenumbers="" then
invalidmobilenumbers=mobilenumberarray(i)
else
invalidmobilenumbers=invalidmobilenumbers & "," & mobilenumberarray(i)
end if 'invalidmobilenumbers
end if 'isnumeric
next
sql="insert into leads(mobilenumber,dtime) values"&sql
sql=left(sql,len(sql)-1)
'response.Write(sql)
if tostore<>"" then
conn.execute sql
end if
if tostore<>"" then
response.Write("<font color='green' size=2><center>Mobile Numbers Stored Successfully </center></font><br>")
end if
'if invalidmobilenumbers<>"" then
'response.Write("<font color='red' size=2><center>Invalid Mobile Numbers not Stored are " & invalidmobilenumbers & "<br> </center></font><br>")
' end if
else
response.write er
end if
end if 'flag
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Import Mobile Clients</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="left" style="padding-left:20px;padding-top:20px;padding-bottom:15px;"><strong><font color="#3333CC" size="4">Upload Mobile Leads </font></strong></div>
<form name="uploadmobileleads" action="uploadmobileleads.asp" method="post">
<%
'confirm=request.querystring("confrim")
'if confirm="" then
%>
<table >
<tr>
<td align="left" valign="top" colspan="1">
<table >
<%
if invalidmobilenumbers<>"" then
invalidmobilenumbersarr=split(invalidmobilenumbers,",")
%>
<tr><td>
<%
response.Write("<font color='red' size=2><center> Invalid Mobile Numbers listed below</center></font> ")
%>
</td></tr>
<%
for i=0 to ubound(invalidmobilenumbersarr)
%>
<tr><td align="center" valign="top">
<%
response.Write(invalidmobilenumbersarr(i) & "<br> ")
%>
</td></tr>
<%
next
end if
%>
</table><!-- inner table closed-->
</td>
</tr>
<tr>
<td align="left" valign="top" colspan="2">
<table id="2">
<%
if alreadystore<>"" then
alreadystorearr=split(alreadystore,",")
%>
<tr><td>
<%
response.Write("<font color='red' size=2><center> Mobile Numbers already exist listed below</center></font> ")
%>
</td></tr>
<%
for i=0 to ubound(alreadystorearr)
%>
<tr><td align="center" valign="top">
<%
response.Write(alreadystorearr(i) & "<br> ")
%>
</td></tr>
<%
next
end if
%>
</table><!-- id=2 inner table closed-->
</td>
</tr>
<tr><td colspan="2" valign="top"><strong>Enter Mobile Number as 9762471857 followed by Enter</strong> </td></tr>
<tr><td align="left" valign="middle">Mobile Number</td>
<td align="left" valign="middle"><textarea rows="30" name="mobilenumber" ></textarea></td>
</tr>
<tr>
<td>
</td>
<td>
<input type="hidden" name="flag" value="1">
<input type="submit" name="submit" value="Import"></td>
</tr>
</table>
<%
'else
'end if
%>
</form>
<% 'conn.close %>
</body>
</html>
推荐答案
很抱歉,我没有时间分析此代码并查找问题.首先看它告诉我,这几乎没有任何意义.只看一个细节:字符串文字"91"重复了6次.如果以后要更改该怎么办.这是不支持的.根本不应该有硬编码的立即数.这种编码几乎与真正的编程无关,也无济于事.如果继续这样工作,则会引发各种错误.
—SA
Sorry, I could not get time to analyze this code and find the problem. First look at it tells me it hardly would make much sense. Look at just one detail: string literal "91" is repeated 6 times. What if later on you want to change it. This is not supportable. There should not be hard-coded immediate constants at all. This coding has almost nothing to do with real programming and will lead nowhere. If you continue working like this, you will invite all kinds of errors.
—SA
尝试调试您的源代码,看看是否可以理解为什么会发生这种情况.
Try debugging your source to see if you can understand why this could be happening.
这篇关于拆分textarea给出了不正确的长度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!