Replace part of string with values in other columns - excel

I am trying to replace a part of string in "input1" with values in column "input2" to get the "output" as shown:
Any idea how to do this in MS excel?

Try below formula-
=SUBSTITUTE(A2,"replace_this",B2)

In addition to the REPLACE and SUBSTITUTE function, if you just need to add something before and/or after some other value (as shown in your picture), you could just use simple concatenation:
="Text-before-value" & B2 & "Text-after-value"

A
B
C
1
Input1
input2
output
2
abc_'replace_this' xyz
replace1
=REPLACE(A2,FIND("replace_this",A2,1),LEN("replace_this"),B2)

Related

How to recover second element separate by character with index equiv

I got a table in Excel like this:
I used index with double equiv to have only the price for column A, the price for column B, the price for column C, I did this :
=INDEX($J$1:$L$4;EQUIV($F6;$J$1:$J$4;0);EQUIV(Z$24;$J$1:$L$1;0))
But I would like to have only the value at the right of ";" but I don't know how to combine with my index and equiv to have only the value 111,1456,44455.
I have this:
EQUIV() is the french name for MATCH() am I right?
If so just use a wildcard-match:
=MATCH("*;"&$F6,$J$1:$J$4,0)
Or the french equivalent:
=EQUIV("*;"&F6;$J$1:$J$4;0)
Your question is not quite clear, I am assuming you have a multiple values separated by semicolon ";" in column Price and now you want a portion of it, in this case only Right, if that is so, here is your solution:
Price
112233;50.99
223344;15.50
3344;150.5
to get the left side, use
=LEFT(C2,LEN(C2)-FIND(";",C2)-1)
here you have to subtract -1 because we don't want to include the semicolon at the end
to get the right side, use
=RIGHT(C2,LEN(C2)-FIND(";",C2))
Result:

Extract words before a specific pattern

I have a column with different names in the rows:
hello_world_xt_x_D3_m6
bye_bye_x_D1_m3
h1_man_xt_x_D3_m6
bonjour_no_x_D1_m12
I would like to remove the ending part which follows the pattern
_x_DN_mZ
where N is a number between 0 and 3 and Z is a number between 0 and 16.
I would like to have
hello_world_xt
bye_bye
h1_man_xt
bonjour_no
I think I should use a combination of search and trim/right, but I do not know how to apply it.
I have tried with =substitute(a2, "_x_D2_m3","") but I do not know how to extend it regardless the numbers which follows D and m
You could use Wildcards (See the ? in the search string)
EDIT: replace second ? with *
Formula: =LEFT(A2,SEARCH("_x_D?_m*",A2)-1)
With data in column A, in B1 enter:
=MID(A1,1,FIND("_x_",A1)-1)
and copy downward:
Would this do?
=LEFT(A2,FIND("_x_",A2)-1)

Find string (from table) in cell in matlab

I want to find the location of one string (which I take it from a table) inside of a cell:
A is my table, and B is the cell.
I have tested :
strncmp(A(1,8),B(:,1),1)
but it couldn't find the location.
I have tested many commands like:
ismember,strmatch,find(strcmp),find(strcmpi)find(ismember),strfind and etc ... but they all give me errors mostly because of the type of my data !
So please suggest me a solution.
You want strfind:
>> strfind('0123abcdefgcde', 'cde')
ans =
7 12
If A is a table and B a cell array, you need to index this way:
strfind(B{1}, A.VarName{1});
For example:
>> A = cell2table({'cde'},'VariableNames',{'VarName'}); %// create A as table
>> B = {'0123abcdefgcde'}; %// create B as cell array of strings
>> strfind(B{1}, A.VarName{1})
ans =
7 12
Luis Mendo's answer is absolotely correct, but I want to add some general information.
Your problem is that all the functions you tried (strfind, ...) only work for normal strings, but not for cell array. The way you index your A and B in your code snippet they still stay a cell array (of dimension (1,1)). You need to use curly brackets {} to "get rid of" the cell array and get the containign string. Luis Mendo shows how to do this.
Modified solution from a Mathworks forum, for the case of a single-column table with ragged strings
find(strcmp('mystring',mytable{:,:}))
will give you the row number.

Excel Find And Replace Text in Formula

I have 3 columns: A and B contain numbers, and C has a html link.
I want to replace numbers in the html link with the numbers from columns A & B.
Can anyone tell me how I can do this? I tried using the replace function, but it doesnt work for multiple variables.
Example:
random.com/do?ID=1111&SourceID=2222
I'd replace 1111 with ID columan A 617 and 2222 with sourceID column B 2
SourceID LocationID link
617 2 random.com/do?ID=1111&SourceID=2222
1878 39 random.com/do?ID=1111&SourceID=2222
4148 48 random.com/do?ID=1111&SourceID=2222
I would not use the replace formula here because it requires a "position and length" which will change once you update the link with a new value from SourceID or LocationID and the logic to figure out the new location is overkill and not needed.
Instead you can use the Substitute formula instead which I think is more readable and easier to implement. This formula replaces "text" with "text"
If you use 2 Substitutes (1 outer and 1 nested) you can replace both strings in one line. Try putting this in column D
=SUBSTITUTE(SUBSTITUTE(C1,"1111",A1),"2222",B1)
and you can auto-fill down

Substring in excel

I have a set of data that shown below on excel.
R/V(208,0,32) YR/V(255,156,0) Y/V(255,217,0)
R/S(184,28,16) YR/S(216,128,0) Y/S(209,171,0)
R/B(255,88,80) YR/B(255,168,40) Y/B(255,216,40)
And I want to separate the data in each cell look like this.
R/V 208 0 32
R/S 184 28 16
R/B 255 88 80
what is the function in excel that I can use for this case.
Thank you in advance.
kennytm doesn't provide an example so here's how you do substrings:
=MID(text, start_num, char_num)
Let's say cell A1 is Hello.
=MID(A1, 2, 3)
Would return
ell
Because it says to start at character 2, e, and to return 3 characters.
In Excel, the substring function is called MID function, and indexOf is called FIND for case-sensitive location and SEARCH function for non-case-sensitive location. For the first portion of your text parsing the LEFT function may also be useful.
See all the text functions here: Text Functions (reference).
Full worksheet function reference lists available at:
    Excel functions (by category)
    Excel functions (alphabetical)
Another way you can do this is by using the substitute function. Substitute "(", ")" and "," with spaces.
e.g.
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1, "(", " "), ")", " "), ",", " ")
I believe we can start from basic to achieve desired result.
For example, I had a situation to extract data after "/". The given excel field had a value of 2rko6xyda14gdl7/VEERABABU%20MATCHA%20IN131621.jpg . I simply wanted to extract the text from "I5" cell after slash symbol. So firstly I want to find where "/" symbol is (FIND("/",I5). This gives me the position of "/". Then I should know the length of text, which i can get by LEN(I5).so total length minus the position of "/" . which is LEN(I5)-(FIND("/",I5)) . This will first find the "/" position and then get me the total text that needs to be extracted.
The RIGHT function is RIGHT(I5,12) will simply extract all the values of last 12 digits starting from right most character. So I will replace the above function "LEN(I5)-(FIND("/",I5))" for 12 number in the RIGHT function to get me dynamically the number of characters I need to extract in any given cell and my solution is presented as given below
The approach was
=RIGHT(I5,LEN(I5)-(FIND("/",I5))) will give me out as VEERABABU%20MATCHA%20IN131621.jpg . I think I am clear.
Update on 11/30/2022
With new excel functions, you can use the following in cell C1 for the input in A1:
=TEXTJOIN(" ",,TEXTSPLIT(A1,{"(",",",")"}))
Here is the output:
What about using Replace all?
Just replace All on bracket to space.
And comma to space. And I think you can achieve it.

Resources