c# equivalent for VB Mid Function?

Posted on 2015-01-07
Last Modified: 2015-01-08
Hi!  I am trying to insert a string into another string, and cannot figure out the correct syntax.  The code here does not work.  Please show me a work around.

public void Say(int iColumn, string s)
            strData.Substring(iColumn,s.Length ) = s;

Open in new window

Question by:Sheryl Landis
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40537212
public void Say(int iColumn, string s)
    string temp = "";
    temp = strData.Substring(0, iColumn) + s + strData.Substring(iColumn);
    strData = temp;

Open in new window

this works.
LVL 86

Accepted Solution

Mike Tomlinson earned 250 total points
ID: 40537245
Why not just do?...
public void Say(int iColumn, string s)
    strData = strData.Insert(iColumn, s);

Open in new window

See String.Insert():
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 250 total points
ID: 40537318

strData = strData.Insert(iColumn, s);

is better solution. You may need to use like

strData = strData.Insert(iColumn + 1, s);

because the first character index in your string starts from 0.

Author Closing Comment

by:Sheryl Landis
ID: 40537634
Great solution!  Thank you

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question