473,320 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

string concatenation

553 512MB
Hi

How to concatenate string at a specific posisition in a string ?

I know we can use Mid() but it overwrites to the previous string.

help please
Aug 10 '07 #1
3 2375
ADezii
8,834 Expert 8TB
Hi

How to concatenate string at a specific posisition in a string ?

I know we can use Mid() but it overwrites to the previous string.

help please
If I interpret you correctly, you want to be able to concatenate "delp" to "Philahia" at position "6" to produce ==> "Philadelphia"
OR
Concatenate "umon" to "Pneia" at position "4" to produce ==> "Pneumonia"

If these assumptions are correct, then this Function will do the trick. Simply pass the Primary String, the String to Add, and the Position at which you want to add the String to the Function. The Function will then return a String Value, and hopefully, the correct response. The Function and associated Call are listed below.
Expand|Select|Wrap|Line Numbers
  1. Public Function fAddStringAtPosition(strMainString As String, strStringToAdd As String, intPosition As Integer) As String
  2. Dim strMyString As String
  3.  
  4. strMyString = Left$(strMainString, intPosition - 1) & strStringToAdd
  5. strMyString = strMyString & Right$(strMainString, Len(strMainString) - (intPosition - 1))
  6.  
  7.   fAddStringAtPosition = strMyString
  8. End Function
  9.  
Expand|Select|Wrap|Line Numbers
  1. Dim strRetValue As String
  2. strRetValue = fAddStringAtPosition("Philahia", "delp", 6)
  3.  
  4. MsgBox "The completed String is: " & strRetValue
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Philadelphia
Aug 10 '07 #2
questionit
553 512MB
Thanks ADezii

I thought there would be a pre-defined function in VB to do this!

If I interpret you correctly, you want to be able to concatenate "delp" to "Philahia" at position "6" to produce ==> "Philadelphia"
OR
Concatenate "umon" to "Pneia" at position "4" to produce ==> "Pneumonia"

If these assumptions are correct, then this Function will do the trick. Simply pass the Primary String, the String to Add, and the Position at which you want to add the String to the Function. The Function will then return a String Value, and hopefully, the correct response. The Function and associated Call are listed below.
Expand|Select|Wrap|Line Numbers
  1. Public Function fAddStringAtPosition(strMainString As String, strStringToAdd As String, intPosition As Integer) As String
  2. Dim strMyString As String
  3.  
  4. strMyString = Left$(strMainString, intPosition - 1) & strStringToAdd
  5. strMyString = strMyString & Right$(strMainString, Len(strMainString) - (intPosition - 1))
  6.  
  7.   fAddStringAtPosition = strMyString
  8. End Function
  9.  
Expand|Select|Wrap|Line Numbers
  1. Dim strRetValue As String
  2. strRetValue = fAddStringAtPosition("Philahia", "delp", 6)
  3.  
  4. MsgBox "The completed String is: " & strRetValue
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Philadelphia
Aug 13 '07 #3
ADezii
8,834 Expert 8TB
Thanks ADezii

I thought there would be a pre-defined function in VB to do this!
There are Functions that perform similar tasks, but to the best of my knowledge, none that perform this specific task.
Aug 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jonas Galvez | last post by:
Is it true that joining the string elements of a list is faster than concatenating them via the '+' operator? "".join() vs 'a'+'b'+'c' If so, can anyone explain why?
20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
3
by: John Ford | last post by:
For simple string concatenation, is there a difference between... Dim s As String s += "add this to string" ....and... Dim s As String s = String.Concat(s, "add this to string")
9
by: Justin M. Keyes | last post by:
Hi, Please read carefully before assuming that this is the same old question about string concatenation in C#! It is well-known that the following concatenation produces multiple immutable...
16
by: Mark A. Sam | last post by:
Hello, I am having a problem with imputting into a string variable: Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany, txtPhone, txtEmail, txtComment, chkGrower,...
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
12
by: Richard Lewis Haggard | last post by:
I thought that the whole point of StringBuilder was that it was supposed to be a faster way of building strings than string. However, I just put together a simple little application to do a...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
10
by: =?Utf-8?B?RWxlbmE=?= | last post by:
I am surprised to discover that c# automatically converts an integer to a string when concatenating with the "+" operator. I thought c# was supposed to be very strict about types. Doesn't it seem...
34
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.