Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which function in C# like Mid() function in VBA? [duplicate]

Tags:

c#

vba

In VBA Access, I get a short string from long string by line below:

tmpStr1,tmpStr2 as string;  
tmpStr1 = "abcdefgh"  
tmpStr2 = Mid(tmmStr1,3,1) 'result is c

How to do same in C#?

like image 276
Plasmazion Avatar asked Sep 14 '25 18:09

Plasmazion


2 Answers

try to do this.

var tmpStr1 = "abcdefgh";
var tmpStr2 = tmpStr1.Substring(3, 1);

Console.WriteLine(tmpStr2);

https://dotnetfiddle.net/WpDrpk

like image 148
Jeric Cruz Avatar answered Sep 16 '25 07:09

Jeric Cruz


Use Substring in c#

string.Substring( int startIndex, int length );

you need to do that like this

tmpStr2 = Substring(tmmStr1,2,1)

https://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspx

like image 26
Yogen Darji Avatar answered Sep 16 '25 07:09

Yogen Darji