Replace n strings
hello,
i have a string that contain some words that i want to replace to other words.
replace can do just one and i want in onw sql to replace n strings.
for example:
i have the string:
"this is a test string and i want to replace several words"
i want to replace the words: test with aaa,want with bbb,several with ccc.
so after it will be:
"this is a aaa string and i bbb to replace ccc words"
how can i do it in one sql or what is the best way to do it ?
thanks
Zvika
You can try to do this with using of MODEL clause.
SELECT cur_val
FROM (SELECT 1 AS dim_col, 'this is a test string and i want to replace several words' AS cur_val FROM dual)
MODEL
DIMENSION BY (dim_col)
MEASURES (cur_val, 1 string_to_replace_num)
UNIQUE DIMENSION
RULES ITERATE (3)
cur_val[1] = replace(cur_val[1],
case string_to_replace_num[1] when 1 then 'test' when 2 then 'want' when 3 then 'several' end,
case string_to_replace_num[1] when 1 then 'aaa' when 2 then 'bbb' when 3 then 'ccc' end
string_to_replace_num[1] = string_to_replace_num[1] + 1
In the row RULES ITERATE (3) - 3 is not a magic number. It is equal to total number of strings have to be replaced.
Similar Messages
-
Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
shapes in Excel Object.
Since the Excel.Application
is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
interact with Excel document.
The figure below is an excel file:
Figure 1.
You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
$text = “text1”,”text2”,”text3”,”text3”
$Excel
= New-Object -ComObject Excel.Application
$Excel.visible = $true
$Workbook
= $Excel.workbooks.open("d:\shape.xlsx")
#Open the excel file
$Worksheet
= $Workbook.Worksheets.Item("shapes")
#Open the worksheet named "shapes"
$shape = $Worksheet.Shapes
# Get all the shapes
$i=0
# This number is used to replace the text in sequence as the variable “$text”
Foreach ($sh in $shape){
$sh.TextFrame.Characters().text
# Get the textbox in the shape
$sh.TextFrame.Characters().text =
$text[$i++]
#Change the value of the textbox in the shape one by one
$WorkBook.Save()
#Save workbook in excel
$WorkBook.Close()
#Close workbook in excel
[void]$excel.quit()
#Quit Excel
Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
Besides, we can also find the documents about these methods and properties in MSDN:
Workbook.Worksheets Property (Excel):
http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
Worksheet.Shapes Property:
http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
Shape.TextFrame Property:
http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
TextFrame.Characters Method (Excel):
http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
Characters.Text Property (Excel):
http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
After running the script above, we can see the changes in the figure below:
Figure 2.
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Thank you for the information, but does this thread really need to be stuck to the top of the forum?
If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
EDIT: I see this is no longer stuck to the top of the forum, thank you.
Don't retire TechNet! -
(Don't give up yet - 13,085+ strong and growing) -
Find and Replace text string in HTML
Opps... I hope this forum is not just for Outlook. My Html files reside on my hard-drive. I am looking for VBA code to open specified file names ####File.html and then find and replace text strings within the html for example "####Name" replaced
with "YYYYY"
I drive the "####File.html" names and the find and replace text strings from an Excel sheet. I am an artist and this Sub would give me time to paint instead of find and replace text. Thank you!
[email protected]Hello Phil,
The current forum is for developers and Outlook related programming questions. That's why I'd suggest hiring anybody for developing the code for you. You may find freelancers, for example. Try googling for any freelance-related web sites and asking such
questions there.
If you decide to develop an Outlook macro on your own, the
Getting Started with VBA in Outlook 2010 article is a good place to start from. -
How to search and replace a string in Excel Shape (textbox) using Powershell.
I have been asked to write a PS script to search/replace a string when found in Excel Shapes when they are textboxes. I have seen lots of simplistic PS scripts and even I can do a "foreach" loop through all the Shapes on a Sheet and display the
Name of each Shape. But I have not found a property or method to expose the actual text in a textbox let alone change it.
I have seen vba script that does this as:
Set xWs = Application.ActiveWorkbook.Worksheets(I)
For Each shp In xWs.Shapes
xValue = shp.TextFrame.Characters.Text
shp.TextFrame.Characters.Text = VBA.Replace(xValue, xFindStr, xReplace, 1)
Next
In Powershell, shp.TextFrame.Characters.Text is ignored and returns nothing. It would be nice to know if this is possible in PS and if so, know how to do it and/or get an example to work from. I would have thought that
PS and VB would use the same Excel object model but apparently they do not.
I am using Excel 14.0 and PS 3.
Any suggestions would be appreciated,
MichaelThis didn't work for me. I have the shape object and it shows the textframe property:
PS C:\> $shape | gm
TypeName: System.__ComObject#{00024439-0000-0000-c000-000000000046}
Name MemberType Definition
Apply Method void Apply ()
CanvasCropBottom Method void CanvasCropBottom (float)
SoftEdge Property SoftEdgeFormat SoftEdge () {get}
TextEffect Property TextEffectFormat TextEffect () {get}
TextFrame Property TextFrame TextFrame () {get}
TextFrame2 Property TextFrame2 TextFrame2 () {get}
ThreeD Property ThreeDFormat ThreeD () {get}
But trying to access it gives an error:
PS C:\> $shape.textframe | gm
gm : You must specify an object for the Get-Member cmdlet.
At line:1 char:20
+ $shape.textframe | gm
+ ~~
+ CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
PS C:\> $shape.TextFrame.Characters().text="hello"
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $shape.TextFrame.Characters().text="hello"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I hope this post has helped! -
Problem in replacing the String in a Fille.
I need to replace the String in the text file, am able to do it partially.
I mean, am able to replace it. But there are some discrepancies if the replacement string is of "less" or "more" in length than the existing one.
I solved it for the replacement string of less size, but am unable to do it for the string of more size.. :(
The problem am facing is "when the replacement string is larger than the existing one, then the other subsequent line in the file gets overwritten".
I have used RandomAccessFile class for reading and writing the same file.
fpointer1 = randomFile.getFilePointer() - strLine.length() - 2;
strLine1 = strLine;
int sInd = strLine1.indexOf('\'');
int eInd = strLine1.indexOf(';');
String oldStr = strLine1.substring(sInd + 1, eInd - 1);
strLine1 = StringUtils.replace(strLine1, oldStr, newStr);
if (oldStr.length() < newStr.length()) {
int diff = (newStr.length() - oldStr.length()) + 1;
randomFile.writeBytes("\r\n");
for (int i = 0; i < diff; i++) {
randomFile.writeBytes(" ");
randomFile.seek(fpointer1);
randomFile.writeBytes(strLine1);
} else if (oldStr.length() > newStr.length()) {
randomFile.seek(fpointer1);
randomFile.writeBytes(strLine1);
int diff = (oldStr.length() - newStr.length()) + 1;
for (int i = 0; i < diff - 1; i++) {
randomFile.writeBytes(" ");
randomFile.writeBytes("\r\n");
break;
}Can u pls help me in resolving this issue???...boopathi wrote:
As u said the overwriting causes the problem, but i managed to resolve for the string of less size.I assume you did this with some padding? That's not exactly a clean solution.
So thats why am seeking to manage the larger size string to replace without overwriting the sub sequent lines.
Can you help me in suggesting whether it can be resolved using the getFilePointer() and seek() methods??...No you can't.
Whether you shorten or lengthen the position where you modify the file, you need to move the remaining bytes back or forward, depending which is the case.
You managed to solve the first case by printing out padding, so you don't need to move the bytes back, but you can't solve the other case like this. You can lengthen the file and move the remaining bytes forward, but I probably wouldn't bother since a simple Reader-based approach is a lot better and easier to get right. -
Batch File Search and Replace a String
I've written a batch file to handle the copying of files. I'm trying to reduce the number of parameters that I pass to the batch file.
I want the batch file to perform a string replace on the directory path that is passed as a parameter to the batch file.
Here is how I run the batch file:
COPY_FILE.BAT C:\DATA\FTP_DATA\ACME\IN (I'm passing directory path "C:\DATA\FTP_DATA\ACME\IN" as parameter %1)
So my batch file will copy a file to the directory path represented by parameter %1.
But then I want the file copied to a second directory. I want the batch file to replace string "FTP_DATA" in the directory path with string "FTP_DATA\ARCHIVE"
I know I could pass this path as a second parameter, but I want to limit the number of parameters so figured I could have the batch file perform a search and replace on string "FTP_DATA".
After searching the internet, I thought I found the answer by using the following command in the batch file:
set ARCHIVE_PATH=%1:FTP_DATA=FTP_DATA\ARCHIVE
But it doesn't perform a search and replace. It just appends to the directory path with the following result:
C:\DATA\FTP_DATA\ACME\IN:FTP_DATA=FTP_DATA\ARCHIVE
What I want is the this:
C:\DATA\FTP_DATA\ARCHIVE\ACME\IN
Any suggestions?Your syntax is not correct. Example:
@echo off
setlocal enableextensions
set ARCHIVE_PATH=C:\DATA\FTP_DATA\ACME\IN
echo %ARCHIVE_PATH%
set ARCHIVE_PATH=%ARCHIVE_PATH:FTP_DATA=FTP_DATA\ARCHIVE%
echo %ARCHIVE_PATH%
endlocal
-- Bill Stewart [Bill_Stewart] -
Replacing a string of character by another one with emacs
Hello,
With Vim, I had something like this in my setup (tex.vim in ftplugin)
imap <buffer> ... \ldots
imap <buffer> « \og
imap <buffer> » \fg
imap <buffer> " \textquotedblleft
imap <buffer> ¢ \textquotedblright\
imap <buffer> € \EUR
imap <buffer>~ $\sim\
imap <buffer> // \\
imap <buffer> /np \newpage
Currently, I am trying emacs, and would like the same setup. I have searched the web, but with no luck. Indeed, I've just found the following code (and made some modifications to try it) :
(defun replace-string-pairs-region (start end mylist)
"Replace string pairs in region."
(save-restriction
(narrow-to-region start end)
(mapc
(lambda (arg)
(goto-char (point-min))
(while (search-forward (car arg) nil t) (replace-match (cadr arg)) )
) mylist
(defun replace-chars (start end)
"Replace "..." by "\ldots" and other similar chars"
(interactive "r")
(replace-string-pairs-region start end '(
("..." "\ldots")
;("<" "<")
;(">" ">")
But it doesn't work.
Does anyone know how could I replace "..." by "\ldots" and other things like that with Emacs ?
Last edited by alexandre (2010-09-28 17:48:50)Thank you a lot for your answer, but my problem was not to replace "..." by "\ldots" after typing it, but how could I replace "..." by "\ldots" while I am typing it, just after I finished to push the last dot.
I have tried to set it up with the abbrev mode, but it seems to work only for words. So for example, if I enter the word such as, say, "arch", then it replace it automatically by "archlinux" after pressing the space key. I won't have to replace the string manually, it does it automatically with the abbreviation mode of Emacs. Here is an example of what I am talking about :
(abbrev-mode t) ; completion automatique
(global-set-key (quote [tab]) (quote dabbrev-expand))
(setq default-abbrev-mode t)
(define-abbrev-table 'global-abbrev-table '(
("..." "\ldots" t)
("arch" "archlinux" nil)
But my problem is, it doesn't work for "...", just for words. Of course, I could do it manually with the shortcut you wrote, but it would be nice to make it work automatically. Is there a way to do so ?
If you don't understand what I am talking about, try Vim, copy "imap <buffer> ... \ldots" in your .vimrc, and Vim will replace all "..." by "\ldots" while typing. I am sure I can do it with Emacs, I just don't know how.
Last edited by alexandre (2010-09-30 12:28:38) -
Replacing multiple strings for many occurance of single string in OBIEE a
Hi,
I have a requirement like i need to replace a Particular string('_') that occur three times in a string.I need to replace different strings for each occurance of ('_').
My requirement is like this,
My string is 'A_B_C_D' and I need to replace first'_' as 'E=' second '_' as 'F=' third '_' as 'G='.
and the final string should be I=A E=B F=C G=D...
Can any one help me in the logic or else help me how to use the existing functions in answers.Hi,
We have Replace function in Answers which would replace all occurunces of a particular character with another. To achieve your requirement, you will need to split your string and apply replace function on each part and finally concatenate again.
For e.g. your string is 'A_B_C_D'
You need to split into, below
A_
B_
C_
D
Apply Replace function to first three parts and then finally concatenate.
Replace('A_','_','E=') || Replace('B_','_','F=') || Replace('C_','_','G=') || 'D'
To split the string into parts you may have to use substring and locate functions.
Refer the below thread too.
Re: extract a part of a string in a full string
Thanks -
How to find and replace any string between " "
Hi everyone,
Here my sample
String szTest;
szTest = "Yellow banana";
szTest = "Blue monkey";
szTest = "Red mango";
szTest is only needed when it's in testing progress. Now I want to put all of that in the /*comment*/ so the released program won't run those code any more (but still keep szTest so I can use it for future develop testing).
So Here what I want after using the Find and Replace Box:
//String szTest; //Manual
/*szTest = "Yellow banana";*/ //use find and replace
/*szTest = "Blue monkey";*/ //use find and replace
/*szTest = "Red mango";*/ //use find and replace
I think I can do this with Regular expressions or Wildcards. But I don't know how to find and replace any string between " and ".
Find: szTest = " ??Any string?? ";
Replace with: /*szTest = " ??Any string?? ";*/
Thanks for reading.Hi Nathan.j.Smith,
Based on your issue, I suggest you can try the Joel's suggestion check your issue again. In addition, I find a MSDN document about how to use the Regex.Replace Method to match a regular expression pattern with a specified replacement string,
maybe you will get some useful message.
https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx
If the above suggestion still could not provide you, could you please tell me what language you use to create the program for finding and replace any string using regular expression so that we will find the correct programming develop forum to support this
issue?
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
I have the following string:
String="TVBeginEsternTVEnd
MovieBeginN/AMovieEnd
TVBeginPacificTVEnd
MovieBeginN/AMovieEnd......................"
I need to replace only the contents between TVBegin and TVEnd. The result (If I want the content=Midwest) should look as follow:
String="TVBeginMidwestTVEnd
MovieBeginN/AMovieEnd
TVBeginMidwestTVEnd
MovieBeginN/AMovieEnd......................"
Do you have any suggestions on how to replace the string content?
Thank you very much!Sheshy,
We can tell you how to do small things, one at a time, all day long. You really need to learn how to read the documentation. Go read the documentation for String, StringBuffer. You can figure it out. Really. -
Replace a string in a character field with a amount value
Hi,
I have a text field in which I want to replace a string with an amount value. while am trying to replace it , it gives me some empty space.
For example:
amount = '1200 '
message = 'The STIP amount is &1'
in my code :
replace &1 with message into message.
the result is
'The STIP amount is 1200 '
I dont want the space after 1200.
I tried for condense no-gaps also but it is not working ..
What may be the problem?
Can you suggest some solution for this?
Regards,
VimalaHi,
replace &1 with message into message.
I guess its replace &1 with amount into message.
Convert the amount to a character type (example move amount to amount_c ), then condense it and and then replace it using the 'REPLACE' statement.
regards,
Advait. -
Replace a string with another string in a file
I have to replace a string with another string. Say for example in a html file it got a line like,
<a href="##"></a>
now i want to replace this ## with the full derived path like
"c;\\sample folder\\sample subfolder\\samplefile.html"
can someone help me to do this?
pls tell me from the file opening till closing the file.I have to replace a string with another string. Say
for example in a html file it got a line like,
<a href="##"></a>
now i want to replace this ## with the full derived
path like
"c;\\sample folder\\samplesubfolder\\samplefile.html"
can someone help me to do this?
pls tell me from the file opening till closing the
file.
public class Buckel {
final static String CONST = "c:\\sample folder\\samplesubfolder\\samplefile.html";
public Buckel() {
public static void main ( String[] argv ) throws Exception {
int idx = 0;
String in = "<a href=\"##\"></a>", // We'll imagine this just gets here somehow. If it's on the i/p file then take the '\' out B4 and aft the '##'.
out = "";
idx = in.indexOf( "##" );
if ( idx > 0 ) {
out = in.substring( 0, idx ) + CONST + in.substring( idx+=2, in.length() );
System.out.println( out );
} -
Stringbuilder replacement of string ?
can we say stringbuilder is replacement of string class. Because stringbuilder provides all features of string with mutability advatange. i mean whereever we used string in past we can simply use stringbuilder in plase of that ?
JavaFunda wrote:
Yes i agree its a programming error if we dont declare source variables as synchronized . But i am trying to understand if we dont declare source variables(say one is string and another is strinbuilder) as synchronized, how come string immutability provides the advantage over string builder mutability in? Thats the only intention of question. sorry for inconvenience.First, you can't declare variables as synchronized; you can only declare them as 'volatile', which is slightly different.
The advantage of an immutable object, be it String or any other type, is that you know it can't change. That means that you can hand it around in a multi-threaded environment secure in the knowledge that Thread B will see the same value as Thread A. If you hand around a StringBuilder, you have no such guarantee because any third party that has access to the same object can change it.
There is also a category of objects called "Thread-safe", but it's too big a topic to go into here. I suggest you read up on the subject in the tutorials or via Google. I'll just say this: immutable objects are Thread-safe by definition.
Other than the exception I listed above, the only real advantage of a StringBuilder is that you can sometimes build String-like values faster and more concisely with it than you can with String (and in most cases we're talking nanoseconds of difference). If you're dealing with very large iterations, it may make a difference (particularly in space), and it's also more likely that code that uses StringBuilder will run in more constant time; but you still have the overhead of having to convert back to Strings at some point, because far more methods take Strings than StringBuilders.
Winston -
Replace a string except it was replaced
Hey guys:
I met a big problem and would you guys do me a big favour?
I want to replace a part of a text String by some other Strings.
for example,I want to replace the String "ab" into "cd",and the String "cd" into "xx" from the text "abcdefg", and what I expected result is "cdxxefg",but if i call the methodYou rperformance has been praiseworthy. Andthere's
no one else to blame but you :)I agree. And, may I please take the blame foryour
typo?It's a conspiracy... that space moved after I posted.
Blame it on... dunno who :)Got to let this poor OP get back to his/her thread, but , keep on blaming it on me. I am a conspiracy all on my own.
RD-R
� {� -
Replace a string single quote(') with underscore(_)
I have more than 100 tables in a schema.
I have to find out if a string has a single quote in the column and replace it with an underscore.
I have 2 columns CREATE_USER and UPDATE_USER in all the tables. Now i want to update the values if the string has a single quote in it.
I tried it with execute immediate but it is not allowing underscore in the statement.
DECLARE
v_table_name VARCHAR2 (30);
v_column_name VARCHAR2 (30);
CURSOR c_name
IS
SELECT DISTINCT table_name, column_name
FROM user_tab_cols
WHERE column_name IN ('LOGIN', 'CREATE_USER', 'UPDATE_USER')
AND table_name NOT LIKE '%JN';
BEGIN
FOR rec IN c_name
LOOP
v_table_name := rec.table_name;
v_column_name := rec.column_name;
EXECUTE IMMEDIATE 'update '
|| v_table_name
|| ' set '
|| v_column_name
|| ' = REPLACE('
|| v_column_name
|| ','''',"_") where '
|| v_column_name
|| ' like "%''%"';
END LOOP;
END;
/i am getting the below error:
ORA-00904: "%'%": invalid identifier
ORA-06512: at line 17Can anyone let me know what is the error in the statement and how to overcome itplease try to replace your execute immediate with:
EXECUTE IMMEDIATE 'update '
|| v_table_name
|| ' set '
|| v_column_name
|| ' = REPLACE('
|| v_column_name
|| ','''''''',''_'') where '
|| v_column_name
|| ' like ''%''''%''';You can check the statement when you take a look at the construction before like this:
declare
v_sql varchar2(1000);
begin
v_sql:= 'update '
|| v_table_name
|| ' set '
|| v_column_name
|| ' = REPLACE('
|| v_column_name
|| ','''''''',''_'') where '
|| v_column_name
|| ' like ''%''''%''';
dbms_output.put_line(v_sql);
execute immediate v_sql;
...Edited by: hm on 23.11.2010 01:43
Maybe you are looking for
-
Can't open .cr2 files in Bridge CS4 v.3
Been browsing for hours; can't find the right answer... I just purchased a Canon 60D, which shoots .cr2 raw files. They won't open in Bridge, which previously opened my Canon 10D .crw raw files. What do I need to do to make the .cr2 files open? I'd r
-
Problems with External Monitor In XP
Ok, I've got a huge problem with XP on Bootcamp. I've recently got a Samsung TV which I can use as an external monitor. This works absolutely fine when I'm using OSX, recognizes the TV and can use it as a second screen. When I try to use the same mon
-
Can't open Aperture 3 on my laptop. Just sits there spinning while saying it "Opening Aperture Library."
-
Photos edited in iOS 8 do not transfer to iphoto on MAC
I edited over 78 photos in iOS 8 which was really easy and wonderful. However, it seems all that work was for naught. I cannot transfer them to my computer. It transfers only the original photo it seems.
-
Automatically estimate all pending MROs
Dear All There is a business scenario in the implementation i m doing, which requires all the pending MROs to be estimated (via a custom estimation logic) after say 2 days have been crossed from the scheduled meter read date I configured the Automati