[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


c# equivalent for VB Mid Function?

Posted on 2015-01-07
Medium Priority
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 1000 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 1000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 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