-2

In VB6 I can use following code to change part of string with another string..

For example:

Dim strTest As String
strTest = "abc"
Mid$(strTest, 2, 1) = "x"
' now strTest Value will be "axc"

Is there any VB.Net equivalent for above? String.Replace will replace all instance but I don't want that.

ekad
  • 14,436
  • 26
  • 44
  • 46
Zakir_SZH
  • 466
  • 7
  • 21
  • 1
    i don't understand why i get down vote? is asking question is wrong here? – Zakir_SZH Sep 21 '14 at 08:11
  • Your question was down voted because it seems that you didn't do any research on your own. Typing _VB.Net Mid$_ in Google returns many many hits that would have helped you. – Chris Dunaway Sep 22 '14 at 15:26

1 Answers1

5

Use VB.NET Mid statement. The code below will produce the same results as your VB6 code.

Dim strTest As String
strTest = "abc"
Mid(strTest, 2, 1) = "x"
GSerg
  • 76,472
  • 17
  • 159
  • 346
ekad
  • 14,436
  • 26
  • 44
  • 46
  • Dear sir, Mid is not vb.net sole function. you need to use vb6 names space what i don't want to use :( – Zakir_SZH Sep 21 '14 at 08:11
  • 3
    It is the MID *statement*, not the function. Has been part of Basic for a very, very long time. And still is today, nothing to do with "vb6 names space". The VB.NET compiler transforms it into a helper method call, Microsoft.VisualBasic.CompilerServices.StringType::MidStmtStr(), included with the Microsoft.VisualBasic.dll assembly. Which you always use in a VB.NET program. – Hans Passant Sep 21 '14 at 09:26
  • 1
    @HansPassant The OP is [against using VB in VB](http://stackoverflow.com/questions/25951997/equivalent-code-of-createobject-in-vb-net#comment40629814_25951997) for some reason. – GSerg Sep 21 '14 at 09:46
  • @HansPassant, pardon me, i am sorry that's my fault. But i don't know for some wired reason vb.net shows error on that statement/line. But not it is not showing ;( very wired. Thanks though – Zakir_SZH Sep 21 '14 at 11:58
  • @user - clearly you did a very shoddy job of asking this question. [Read this](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Hans Passant Sep 21 '14 at 12:10