在.NET中替换VB6 Mid()? [英] Replacement for VB6 Mid() in .NET?

查看:58
本文介绍了在.NET中替换VB6 Mid()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.NET中寻找功能上相当于VB6 Mid()函数的
,它允许我用
替换字符串的一部分

另一个字符串的特定位置。我想要做的是建立一个固定的

长度的数据记录,首先是一串空白和

然后在
内的特定点下降数据
字符串。 .NET字符串都不是或者StringBuilder

类似乎有这个功能,除非我这样做是为了两个步骤的删除然后再插入。任何

的建议?


- 史蒂夫

解决方案

如果你知道的话你想要取代什么,然后string.Replace可能适用于你的b
$ b" Steve S." < SC ******* @ yahoo.com>在消息中写道

news:01 **************************** @ phx.gbl ... < blockquote class =post_quotes>我在.NET中寻找功能相当于VB6 Mid()函数的东西,它允许我用特定位置替换字符串的一部分
另一个字符串。我想要做的是建立一个固定的长度数据记录,从一串空白开始,然后在
字符串中的特定点放入数据。 .NET字符串都不是或者StringBuilder类似乎具有此功能,除非我将其作为两步删除然后插入的过程。任何
建议?

- 史蒂夫



我不在我的编译器附近但是尝试:


public shared sub MID(byref Str as String,byval Start as

Integer,ByVal Length as integer,byval Value as String,

可选的byval Trunc as boolean = false)


如果Trunc那么

str = str.substring(0,s-1).concat(Value.substring

(0,l),str.Substring(s + l-1)

else

str = str.substring(0,s -1).concat(Value,str.Substring(s + l-

1)

结束如果


end sub


史蒂夫,

使用你一直以来所做的,你所谈论的功能几乎都是来自
VB6(不是全部)仍然存在于VB.net中,但是你现在也可以使用其他的

。但是你为什么要这样做?


(我不是''使用它们,但我不习惯它们。)


Cor


I am looking for something in .NET that is functionally
equivalent to the VB6 Mid() function, which allows me to
replace a portion of a string at a specific position with
another string. What I am trying to do is build a fixed
length data record by starting with a string of blanks and
then dropping in data at specific points within the
string. Neither the .NET "String" or "StringBuilder"
classes seem to have this functionality, unless I do it as
a two-step process of Remove and then Insert. Any
suggestions?

-- Steve

解决方案

If you know what you are trying to replace then string.Replace may work for
you.
"Steve S." <sc*******@yahoo.com> wrote in message
news:01****************************@phx.gbl...

I am looking for something in .NET that is functionally
equivalent to the VB6 Mid() function, which allows me to
replace a portion of a string at a specific position with
another string. What I am trying to do is build a fixed
length data record by starting with a string of blanks and
then dropping in data at specific points within the
string. Neither the .NET "String" or "StringBuilder"
classes seem to have this functionality, unless I do it as
a two-step process of Remove and then Insert. Any
suggestions?

-- Steve



I''m not near my compiler but try:

public shared sub MID(byref Str as String, byval Start as
Integer, ByVal Length as integer, byval Value as String,
optional byval Trunc as boolean = false)

if Trunc then
str = str.substring(0,s-1).concat(Value.substring
(0,l),str.Substring(s+l-1)
else
str = str.substring(0,s-1).concat(Value,str.Substring(s+l-
1)
end if

end sub


Steve,
Use what you are always did, the functions you are talkin about are almost
all from VB6 (not all) still existing in VB.net, but you can use others too
now. But why would you?

( I don''t use them, but I''am not so used to them).

Cor


这篇关于在.NET中替换VB6 Mid()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆