Instr,Trim,Left,Right等函数的命名空间

hornbills 2004-04-29 07:28:07
Imports System
Imports System.String
Namespace Yifang
public class TextFromDB
'只取第一行或者而且不超过20个字符
Public Function ToTitle(strSource as String)
Dim strResult as String
strResult=Trim(strSource)
If InStr(strResult,CHR(13))>0 then
strResult=Left(strResult,InStr(strSource,CHR(13)))
End If
If strResult.Length>20 Then
strResult=strResult.Substring(0,20)+"…"
End If
Return strResult
End Function
End class
End Namespace

不行!
...全文
351 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
huojianfei 2004-09-22
  • 打赏
  • 举报
回复
还有一个问题,就是Substring(0,20)当字符串小于20的时候,报错。
hornbills 2004-04-29
  • 打赏
  • 举报
回复
不用导入 System.String
只用导入 System就行了,而且是Convert.ToChar才需要的
hornbills 2004-04-29
  • 打赏
  • 举报
回复
问题已经解决
用String.IndexOf() 替代 InStr()
用String.Substring() 替代 Left()
用String.Trim() 替代 Trim()
用Convert.ToChar 替代 Chr()

只需要导入 System 和 System.String就行了!
谢谢大家的帮助。

------------------------------------------------------------------
Imports System
Imports System.String

Namespace Yifang
public class TextFromDB
Public Function ToTitle(strSource as String)
Dim strResult as String
strResult=strSource.Trim()
If strResult.IndexOf(Convert.ToChar(13))>0 then
strResult=strResult.Substring(0,strResult.IndexOf(Convert.ToChar(13)))
End If
If strResult.Length>20 Then
strResult=strResult.Substring(0,20)+"…"
End If
Return strResult
End Function
End class
End Namespace
wangsaokui 2004-04-29
  • 打赏
  • 举报
回复
Imports Microsoft.VisualBasic
试过了,需要重新生成解决方案才行,否则编译还是通不过,
wangsaokui 2004-04-29
  • 打赏
  • 举报
回复

Microsoft.VisualBasic.Left,
Microsoft.VisualBasic.Instr,
Microsoft.VisualBasic.Trim,
Microsoft.VisualBasic.Right
smx717616 2004-04-29
  • 打赏
  • 举报
回复
Imports System.String 没有这个命名空间吧,只是类而已
Imports System
Imports Microsoft.VisualBasic.Strings
Namespace Yifang
public class TextFromDB
'只取第一行或者而且不超过20个字符
Public Function ToTitle(strSource as String)
Dim strResult as String
strResult=Trim(strSource)
If InStr(strResult,CHR(13))>0 then
strResult=Left(strResult,InStr(strSource,CHR(13)))
End If
If strResult.Length>20 Then
strResult=strResult.Substring(0,20)+"…"
End If
Return strResult
End Function
End class
End Namespace

看行不行
wangsaokui 2004-04-29
  • 打赏
  • 举报
回复
注意也许要先引用Microsoft.VisualBasic.dll才行
hornbills 2004-04-29
  • 打赏
  • 举报
回复
Imports System
Imports System.String

Namespace Yifang
public class TextFromDB
'只取第一行或者而且不超过20个字符
Public Function ToTitle(strSource as String)
Dim strResult as new String

strResult=strSource.Trim()

If strResult.IndexOf(Chars(13)) then
strResult=strResult.SubString(0,strResult.IndexOf(Chars(13)))
End If

If strResult.Length>20 Then
strResult=strResult.Substring(0,20)+"…"
End If
Return strResult
End Function
End class
End Namespace

改了改,不用Microsoft.VisualBasic,用 system.String
编译错误出在IndexOf

D:\www\bin>call "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tool
s\vsvars32.bat"
Setting environment for using Microsoft Visual Studio .NET 2003 tools.
(If you have another version of Visual Studio or Visual C++ installed and wish
to use its tools from the command line, run vcvars32.bat for that version.)

D:\www\bin>vbc /t:library /out:yifang.dll *.vb /r:System.web.dll /r:System.data.
dll /r:system.dll /r:System.Xml.dll
Microsoft (R) Visual Basic .NET 编译器版本 7.10.3052.4
用于 Microsoft (R) .NET Framework 版本 1.1.4322.573
版权所有 (C) Microsoft Corporation 1987-2000。保留所有权利。

D:\www\bin\Business_public.vb(8) : error BC30516: 没有可访问的“New”接受此数目
的参数,因此重载决策失败。

Dim strResult as new String
~~~~~~~~~
D:\www\bin\Business_public.vb(12) : error BC30518: 重载决策失败,原因是没有可访
问的“IndexOf”可以用这些参数调用:
'Public Function IndexOf(value As String) As Integer': 对非共享成员的引用要
求对象引用。
'Public Function IndexOf(value As Char) As Integer': 对非共享成员的引用要求
对象引用。

If strResult.IndexOf(Chars(13)) then
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\www\bin\Business_public.vb(13) : error BC30518: 重载决策失败,原因是没有可访
问的“IndexOf”可以用这些参数调用:
'Public Function IndexOf(value As String) As Integer': 对非共享成员的引用要
求对象引用。
'Public Function IndexOf(value As Char) As Integer': 对非共享成员的引用要求
对象引用。

strResult=strResult.SubString(0,strResult.IndexOf(Chars(13))
)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~


D:\www\bin>pause
请按任意键继续. . .
hornbills 2004-04-29
  • 打赏
  • 举报
回复
不行啊!!

系统报错
hychieftain 2004-04-29
  • 打赏
  • 举报
回复
MSDN里就有
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/vblr7/html/vafctLeft.htm
注意也许要先引用Microsoft.VisualBasic.dll才行

huangsuipeng 2004-04-29
  • 打赏
  • 举报
回复
:)顶
wangsaokui 2004-04-29
  • 打赏
  • 举报
回复
错了!
import Microsoft.VisualBasic
wangsaokui 2004-04-29
  • 打赏
  • 举报
回复
using Microsoft.VisualBasic;

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧