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
3 2375
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. -
Public Function fAddStringAtPosition(strMainString As String, strStringToAdd As String, intPosition As Integer) As String
-
Dim strMyString As String
-
-
strMyString = Left$(strMainString, intPosition - 1) & strStringToAdd
-
strMyString = strMyString & Right$(strMainString, Len(strMainString) - (intPosition - 1))
-
-
fAddStringAtPosition = strMyString
-
End Function
-
-
Dim strRetValue As String
-
strRetValue = fAddStringAtPosition("Philahia", "delp", 6)
-
-
MsgBox "The completed String is: " & strRetValue
OUTPUT:
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. -
Public Function fAddStringAtPosition(strMainString As String, strStringToAdd As String, intPosition As Integer) As String
-
Dim strMyString As String
-
-
strMyString = Left$(strMainString, intPosition - 1) & strStringToAdd
-
strMyString = strMyString & Right$(strMainString, Len(strMainString) - (intPosition - 1))
-
-
fAddStringAtPosition = strMyString
-
End Function
-
-
Dim strRetValue As String
-
strRetValue = fAddStringAtPosition("Philahia", "delp", 6)
-
-
MsgBox "The completed String is: " & strRetValue
OUTPUT:
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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?
|
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...
|
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")
|
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...
|
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,...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
| |