Solved

c# equivalent for VB Mid Function?

Posted on 2015-01-07
4
117 Views
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.
Thanks!

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

Open in new window

0
Comment
Question by:Sheryl Landis
[X]
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
4 Comments
 
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);
    MessageBox.Show(temp.ToString());
    strData = temp;
}

Open in new window


this works.
0
 
LVL 86

Accepted Solution

by:
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():
http://msdn.microsoft.com/en-us/library/system.string.insert(v=vs.110).aspx
0
 
LVL 34

Assisted Solution

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

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.
0
 

Author Closing Comment

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

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