转换

2013-12-11 46 views
0

VB6代码如下:转换

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

我试着保持逻辑将其更改为C#时,但似乎没有工作。

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

(VB6)InStr函数是(C#)的indexOf
参见:http://bytes.com/topic/net/answers/108174-c-equilivant-instr

(VB6)Right是(C#)Substring,我下面怎么变彼此的模板。 请参阅:http://social.msdn.microsoft.com/Forums/vstudio/en-US/9598905f-912f-4ea7-b954-eb2f48328ce5/c-equivalent-for-right-of-vb

期待:111111fiddlein

获得:111111o> _fiddlein

而且,在最后编辑+ 7当它似乎并没有消除拼接之间的下划线。
但是我得到:111111o> _fiddlein

+0

'tablename.Length,tablename.Length'? – Ralf

+0

是啊,我明白这是不需要的,即时通讯只是遵循如何建议使用什么被认为是等效的。 – jerome

+0

例如,'tablename'包含什么? – Andy

回答

3

我假设如下:

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

那么这个应该这样做:

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

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