简体   繁体   English

从VB6转换为C#字符串操作

[英]Conversion from VB6 to C# string manipulation

VB6 code is as follows: VB6的代码如下:

record = Collection & Right(TableName, Len(TableName) - (InStr(1, TableName, "_<idNo>_") + 7))

I've tried keeping the logic when changing it to c# but doesnt seem to work. 我尝试将逻辑更改为c#时保持逻辑,但似乎不起作用。

collection = 111111   
Record = collection + tablename.Substring(tablename.Length -  tablename.Length - tablename.IndexOf("_<idNo>_", 1) + 7);

(VB6)InStr is (C#)indexOf (VB6)InStr是(C#)indexOf
See: http://bytes.com/topic/net/answers/108174-c-equilivant-instr 请参阅: http : //bytes.com/topic/net/answers/108174-c-equilivant-instr

(VB6) Right is (C#) Substring and I'm following the template of how they change one to another. (VB6) Right是(C#) Substring ,我正在遵循它们如何相互转换的模板。 See: http://social.msdn.microsoft.com/Forums/vstudio/en-US/9598905f-912f-4ea7-b954-eb2f48328ce5/c-equivalent-for-right-of-vb 请参阅: http : //social.msdn.microsoft.com/Forums/vstudio/en-US/9598905f-912f-4ea7-b954-eb2f48328ce5/c-equivalent-for-right-of-vb

Expecting: 111111fiddlein 期望值:111111fiddlein

Getting: 111111o>_fiddlein 正在获取:111111o> _fiddlein

Also, when editing the + 7 at the end it doesn't seem to eliminate the underscore between the concatenation. 另外,在最后编辑+ 7时,似乎并不能消除连接之间的下划线。
But instead I get: 111111o>_fiddlein 但是我得到了:111111o> _fiddlein

I assume the following: 我假设以下内容:

string collection = "111111";
string tablename = "t_<idNo>_fiddlein"; // anything before '<idNo>_' will not be observed

Then this should do it: 然后应该这样做:

string result = collection + tablename.Substring(tablename.IndexOf("_<idNo>_") + 8);

您的问题是VB6 InStr函数基于1,而C#IndexOf函数基于0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM