Search and replace with comma
Hello All,
I want some help. Please help me.
I have comma delimited Data. When I’m converting Sting to Array, If two commas exists in between then its displaying “Zero” (because its array propriety ). Instead of that I want to display “NaN” .
Please give me any idea to replace comma to NaN. I tried with Search and Replace but it’s not giving as I expected.
Munna
Solved!
Go to Solution.
Hello GerdW,
Thanks you so much for your reply.
I thought, instead of replacing trailing comma by NaN adding comma before string is more better (because to many string manipulations) But, it’s taking more execution time.
Munna
Attachments:
Search and Replace.vi 415 KB
Similar Messages
-
Search and replace with wildcard?
I always use search and replace with Homesite but I wonder if
there is a way of using a wildcard? I often want to replace text at
the beginning and end of variable text. I mean, if I have this:
<h3>First text</h3>
<h3>Second text here</h3>
What I'd like is, using the * as a wildcard, is to use
something like this:
Replace <h3>*</h3> with <h2>*</h2>
Any ideas? ThanksMake a backup first, in case this doesn't work (although it should).
Use this in the Find field:
countryText = "([^"]*)";
And this in the Replace field:
<countryText>$1</countryText> -
Search and Replace with a picture
Is it possible to search for a specific text (i.e. :-) ) and replace it with a picture (a smiley) throughout the entire document (all text areas)
Thanks for any help!Ahh found it.
in the dialog you can put in replace with: ^c
if you copy the picture you just need to replace it and it works. pretty sweet -
Search and replace with relative paths
On my 4GB site, each page has a relative link to a single
image in a top folder. I want to get rid of all the images. How do
I search for <img src="Access/images/woCmt.gif"> and an img
with any number of relative links such as <img
src="../Access/images/woCmt.gif"> or <img
src="../../Access/images/woCmt.gif"> or more ../s in the src
path. I want a single find to replace each img tag (to that image)
with nothing, that is delete each one. I've looked at using regular
expression with * with no success.Have you tried: [\.\/]*
That will match zero or more . or / characters (which are
special
Regular Expression characters, so they need to be escaped).
HTH,
Randy
> On my 4GB site, each page has a relative link to a
single image in a top
> folder. I want to get rid of all the images. How do I
search for <img
> src="Access/images/woCmt.gif"> and an img with any
number of relative links
> such as <img src="../Access/images/woCmt.gif"> or
<img
> src="../../Access/images/woCmt.gif"> or more ../s in
the src path. I want a
> single find to replace each img tag (to that image) with
nothing, that is
> delete each one. I've looked at using regular expression
with * with no success. -
Search and replace, with pattern matching using a table
I need to inspect a data stream and standardise a set of codes. I need to
1. Match any patterns with a dash character and remove the dash and any following characters, eg BN-S -> BN, BN-SH -> BN, ARG-22 -> ARG, etc.
2. Make a few specific word for word replacements, eg, PAEDSH -> PAED
This is easy to hard code but can it be done using a table of regex substitutions? Can anyone give a pointer or link to some example code? The couple of regex replacement examples I've found use regex to locate but hard code substitutions.
ThanksYou could store all your patterns in a Map. Then iterate over the map inserting the patterns into a regex.
-
Using a variable in a Powershell search and replace string
Hi
a couple of days ago I posted a question about doing a search and replace with wildcards
Search and repalce with Widcards
I got a swift and very helpful answer but now I need to build on it.
In a text file I wanted to replace all the text between two defined words. the script I got was this
$text = 'Some Server this bit of text varies Language stuff'
$text -replace '(.*Server) .+? (Language.*)','$1 it will always say this $2'
It works great but now I want to replace "it will always say this" with a variable and I can't figure out the correct grammar to make this happen.
Can anyone help??
Thanks
AlexHere's one way:
$replace = 'it will aways say this'if ( $text -match '(.*Server) .+? (Language.*)' )
{ "{0} $Replace {1}" -f $matches[1,2] }
else { $text }
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " " -
Hi, I try to search and replace with Dreamweaver a code
Javascript like this :
<!-- eStat -->
<SCRIPT LANGUAGE="JavaScript">
<!--
var _PJS=0;
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="
http://prof.estat.com/js/m.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
if(_PJS)
_estatl('228028157164','229029157161','PR_AID_MA','PRESSE');
//-->
</SCRIPT>
<NOSCRIPT>
<IMG SRC="
http://prof.estat.com/m/web/228028157164?g=229029157161&p=PR_AID_MA&c=PRESSE&st=0&sjs=0"
BORDER="0">
</NOSCRIPT>
<!-- /eStat -->
Some parts of this code like : PR_AID_MA and PRESSE are
different on every pages.
I tried to use regexp but i didn't find the good syntax.
Anyone Know about this and could you give me an exemple ?
thanks.What do you want to replace? And with what?
Mick
frafad wrote:
> Hi, I try to search and replace with Dreamweaver a code
Javascript like this :
>
> <!-- eStat -->
> <SCRIPT LANGUAGE="JavaScript">
> <!--
> var _PJS=0;
> //-->
> </SCRIPT>
> <SCRIPT LANGUAGE="JavaScript" SRC="
http://prof.estat.com/js/m.js"></SCRIPT>
> <SCRIPT LANGUAGE="JavaScript">
> <!--
> if(_PJS)
_estatl('228028157164','229029157161','PR_AID_MA','PRESSE');
> //-->
> </SCRIPT>
> <NOSCRIPT>
> <IMG
> SRC="
http://prof.estat.com/m/web/228028157164?g=229029157161&p=PR_AID_MA&c=PRESS
> E&st=0&sjs=0" BORDER="0">
> </NOSCRIPT>
> <!-- /eStat -->
>
> Some parts of this code like : PR_AID_MA and PRESSE are
different on every
> pages.
>
> I tried to use regexp but i didn't find the good syntax.
>
> Anyone Know about this and could you give me an exemple
> thanks.
>
> -
Search and Replace String throwing the wrong error message with regexp?
This came up in a LAVA thread, and I'm not sure if there's a bug here or not. When using Search and Replace string, and using a regular expression of [(G[b|i])], LabVIEW throws error -4622, "There is an unmatched parenthesis in a regular expression." There are obviously no unmatched parenthesis in that expression, so it seems to me that the wrong error is being thrown. I'm just not sure if that's a syntactically valid regexp. The problem seems to be with nesting [ ]'s inside ( )'s inside [ ]'s. I've tried a couple of regexp resources on the Web, and one suggests it's valid, while the other seems to think it isn't.
Message Edited by eaolson on 03-13-2007 10:33 AM
Attachments:
ATML_StandardUnit2.vi 10 KB
regexp.png 5 KBadambrewster wrote:
I think your regexp is invalid.
In regexps, brackets are not the same as parentheses. Parens are for grouping, while brackets are for matching one of a class of characters. Brackets can not be nested.
If the regexp is replaced with [G[bi]], there is no error, so it's not a matter of nested brackets. I couldn't find anything on the PCRE man page that forbids nested brackets specifically, but it makes sense.
Your expression "[(G[bi])]", therefore parses as a character class which matches '(', 'G', '[', 'b', or 'i' followed by an unmatched paren, and an unmatched bracket.
I don't believe that's the case. Replace the regexp with [(Gbi)], and the error goes away. So it's not a matter of the '(' being literal, and then encountering a ')' without a matching '('.
daveTW wrote:
what string exactly you want to replace? I think the round braces are not right in this case, since they mark partial matches which are given back by "match regular expression". But you don't want to extract parts of the string, you want to replace them (or delete, with empty <replace string>). So if you leave the outer [( ... )] then your RegEx means all strings with either "Gb" or "Gi".
It's not my regular expression. A poster at LAVA was having problems with one of his (a truly frightening one), and this seemed to be the element that was causing the problem. I'm pretty sure that the originator of the regexp meant to use G(b|i), which seems like a complicated way of matching "Gb" or "Gi", if you ask me. -
Problem with search and replace
I'm workin on Windows XP, Dreamwearver 8
When I do a search and replace in a site, the changes will be
made correctly, however, the auto date stamp that I'm using on my
pages will duplicate on random pages and overwrite text This
doesn't occur on all pages, and isn't connected with the actual
change I'm making. Has anyone experienced this?Ok Gary, but...
in a SQLWorksheet write:
ababab
Now Edit -> Replace search for b , replace with \nb
Result (the last b is not replaced):
a
ba
bab
At this point, I want to have my string back on one line: Edit -> Replace search for \n , replace with (nothing here)
Result: The search text "\n" was not found.
And to make it work I have to tick the Regular Expressions checkbox (in this case substitute escaped characters is ignored).
While I agree that "it is good to have a choice", I personally find it confusing: none of the few text editors I use (Linux or OSX) behaves this way.
Regards.
Alessandro -
Search given string array and replace with another string array using Regex
Hi All,
I want to search the given string array and replace with another string array using regex in java
for example,
String news = "If you wish to search for any of these characters, they must be preceded by the character to be interpreted"
String fromValue[] = {"you", "search", "for", "any"}
String toValue[] = {"me", "dont search", "never", "trip"}
so the string "you" needs to be converted to "me" i.e you --> me. Similarly
you --> me
search --> don't search
for --> never
any --> trip
I want a SINGLE Regular Expression with search and replaces and returns a SINGLE String after replacing all.
I don't like to iterate one by one and applying regex for each from and to value. Instead i want to iterate the array and form a SINGLE Regulare expression and use to replace the contents of the Entire String.
One Single regular expression which matches the pattern and solve the issue.
the output should be as:
If me wish to don't search never trip etc...,
Please help me to resolve this.
Thanks In Advance,
KathirAs stated, no, it can't be done. But that doesn't mean you have to make a separate pass over the input for each word you want to replace. You can employ a regex that matches any word, then use the lower-level Matcher methods to replace the word or not depending on what was matched. Here's an example: import java.util.*;
import java.util.regex.*;
public class Test
static final List<String> oldWords =
Arrays.asList("you", "search", "for", "any");
static final List<String> newWords =
Arrays.asList("me", "dont search", "never", "trip");
public static void main(String[] args) throws Exception
String str = "If you wish to search for any of these characters, "
+ "they must be preceded by the character to be interpreted";
System.out.println(doReplace(str));
public static String doReplace(String str)
Pattern p = Pattern.compile("\\b\\w+\\b");
Matcher m = p.matcher(str);
StringBuffer sb = new StringBuffer();
while (m.find())
int pos = oldWords.indexOf(m.group());
if (pos > -1)
m.appendReplacement(sb, "");
sb.append(newWords.get(pos));
m.appendTail(sb);
return sb.toString();
} This is just a demonstration of the technique; a real-world solution would require a more complicated regex, and I would probably use a Map instead of the two Lists (or arrays). -
Search and Replace "Column Break" with "Page Break"?
Hi,
I have been using the "column break" where I really should have been using the "page break". The page break just makes more sense in my layout.
Is there anyway to search and replace the column break with a page break?
Thanks,
Rhek -
Search and replace formulas with AppleScript
Thanks to this forum I've found out that it is possible to search and replace text by other text or formulas with AppleScript in Numbers 3.2
Does anybody have a script to search and replace a formula or a part of a formula by another formula or a partial formula.
For example:
I would like to be able to find:
= Table1::$b$3
and replace this by:
= Table1::$b$4De Signature,
Would this approach work for you...
This is a very neat way edit a complex formula in a single cell....
a) Copy and Paste the formula to a new black page in Pages,
b) Do your Find and Replace, then
c) Copy and Paste the formulae back into the cell in Numbers.
It works like a charm.
Here is an example of how I used this approach...
Original cell formulae:
=AVERAGE(
SMALL(OFFSET(K3,1,0,20,1),1),SMALL(OFFSET(K3,1,0,20,1),2),
SMALL(OFFSET(K3,1,0,20,1),3),SMALL(OFFSET(K3,1,0,20,1),4),
SMALL(OFFSET(K3,1,0,20,1),5),SMALL(OFFSET(K3,1,0,20,1),6),
SMALL(OFFSET(K3,1,0,20,1),7),SMALL(OFFSET(K3,1,0,20,1),8))
Final version of formulae:
=AVERAGE(
SMALL(OFFSET(K3,N1,0,20,1),1),SMALL(OFFSET(K3,N1,0,20,1),2),
SMALL(OFFSET(K3,N1,0,20,1),3),SMALL(OFFSET(K3,N1,0,20,1),4),
SMALL(OFFSET(K3,N1,0,20,1),5),SMALL(OFFSET(K3,N1,0,20,1),6),
SMALL(OFFSET(K3,N1,0,20,1),7),SMALL(OFFSET(K3,N1,0,20,1),8))
Find Replace: be cautious with the Find, to ensure it is unique, in my this example ",1,", to avoid changing the" ,1)"
Enjoy... -
Replacing soft returns with hard returns in search and replace PM7
How do I search and replace soft returns in PM7 with a
hard return? What do I type in the find box?Yes BigJohnD,
That is the answer! Thanks so much.
I had hunted for that chart but had not found it yet.
Thanks again, You have been so helpful.
MargoHollis -
Search and replace string function
Hello, I am using the "search and replace string" function and it does nt seem to work consistently for me. I am using it in a situation where I am taking an array of strings, converting this into a spreadsheet string then deleting all of the commas. Has anyone experienced the same behavior? I have searched through other posts and found other simular faults but none of the fixes worked for this. I can post the code it needed.
Thanks,
AndrewI agree that commas are often not desirable, especially if your software should also work in countries where comma is used as a decimal seperator.
Where are the commas coming from? Does (1) each element of the original array have one (or more), do you (2) use comma as seperator if you convert it to a spreadhseet string?
For (1), you might just strip out the comma for each element right in the loop. For case (2) you would simply use a different separator to begin with, of course.
Btw: you are abusing a WHILE loop as a FOR loop, because you have a fixed number of iterations. Please replace it with a FOR loop. If you use a FOR loop, LabVIEW can manage memory much more efficiently, because it can allocate the entire output array before the loop starts. For While loops, the total number of iterations is not known to the compiler. (Of course a real program would also stop the loop if an error occurs. In this case you would need to stay woth the WHILE loop. )
Do you have a simple example how the raw array elements look like. How many commas are there?
LabVIEW Champion . Do more with less code and in less time . -
Find and replace with multiple files and with a watch folder
I am trying to create a watch folder that uses red_menace script to:
1. Have a folder that receives multiple xml files that run the script one by one.
2. then move the files to an output folder.
I tried modifying the set TheFIle to choose file -- the original text file to:
with multiple selections allowed
But that doesn't seem to work. I know i'm missing a step. Any help is much appreciated!
Thanks!
The way i'd like to setup things is having an input folder on the desktop (or just have the application on the desktop and I can drag the files onto it), and let it do it's thing. Once it's done have it export the xml files into an output folder.
Here's what i got so far:
on open
set TheFIle to choose file -- the original text file
set TheFolder to ("Macintosh HD:Users:user1:Desktop:out") -- the folder for the output file
set TheName to (GetUniqueName for TheFIle from TheFolder) -- the name for the output file
set TheText to read TheFIle -- get the text to edit
set Originals to {"KPCALDATE", "KPCALEVENT", "KPCALDAY", "KPCALBODY", "obituaries name", "" & return & "</cstyle></pstyle>" & return & "<pstyle name=\"obituaries text\"><cstyle>", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\" font=\"ADV AGBook-Medium 2\">", "<pstyle name=\"Recipe Ingredients\"><cstyle>", " .com", " .net", " .org", " .edu", "www .", "www. ", "Ho- nolulu", "<pstyle name=\"kicker 12\"><cstyle allcaps=\"1\">fashion news</cstyle><cstyle allcaps=\"1\">" & return & "</cstyle></pstyle>" & return & "", "<component name=\"Headline 1\" type=\"Headline\">" & return & "<header>" & return & "<field name=\"Component name\" type=\"string\" value=\"Headline 1\"/>" & return & "<field name=\"Component type\" type=\"popup\" value=\"Headline\"/>" & return & "</header>" & return & "<body>" & return & "<pstyle name=\"hed STANDARD 36\"><cstyle>", "<pstyle name=\"obituaries text\"><cstyle allcaps=\"1\">", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\">", "<pstyle name=\"tagline\"><cstyle>-", "-", "
Per serving:", "<pstyle name=\"Titlebar - mini, red\"><cstyle allcaps=\"1\">NATION & World </cstyle><cstyle allcaps=\"1\">Report</cstyle><cstyle allcaps=\"1\">" & return & "</cstyle></pstyle>" & return & "", "</cstyle></pstyle>"} -- the terms that can be replaced
set Replacements to {"subhed", "subhed", "subhed", "Normal", "obituaries text", ", ", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\" font=\"ADV AGBook-Medium 2\">", "<pstyle name=\"Recipe Ingredients\"><cstyle>
", ".com", ".net", ".org", ".edu", "www.", "www.", "Honolulu", "", "<component name=\"Headline1\" type=\"Headline\">" & return & "<header>" & return & "<field name=\"Component name\" type=\"string\" value=\"Headline1\"/>" & return & "<field name=\"Component type\" type=\"popup\" value=\"Headline\"/>" & return & "</header>" & return & "<body>" & return & "<pstyle name=\"hed STANDARD 27\"><cstyle>", "<pstyle name=\"obituaries text\"><cstyle allcaps=\"1\">", "<pstyle name=\"obituaries text\"><cstyle name=\"Graphics Bold leadin\">", "<pstyle name=\"tagline\"><cstyle>", " ", "
Per serving:", "","" & return & "</cstyle></pstyle>"} -- the replacement terms
repeat with AnItem from 1 to count Originals
set TheText to (replaceText of TheText from (item AnItem of Originals) to (item AnItem of Replacements))
end repeat
try -- write a new output file
tell application "Finder" to make new file at TheFolder with properties {name:TheName}
set OpenFile to open for access (result as alias) with write permission
write TheText to OpenFile starting at eof
close access OpenFile
on error errmess
try
log errmess
close access OpenFile
end try
end try
end open
to GetUniqueName for SomeFile from SomeFolder
check if SomeFile exists in SomeFolder, creating a new unique name if needed
parameters - SomeFile [mixed]: a source file path
SomeFolder [mixed]: a folder to check
returns [text]: a unique file name and extension
set {Counter, Divider} to {"00", "_"}
-- get the name and extension
set {name:TheName, name extension:TheExtension} to info for file (SomeFile as text)
if TheExtension is missing value then set TheExtension to ""
set TheName to text 1 thru -((count TheExtension) + 2) of TheName
set NewName to TheName & "." & TheExtension
tell application "System Events" to tell (get name of files of folder (SomeFolder as text))
repeat while it contains NewName
set Counter to text 2 thru -1 of ((100 + Counter + 1) as text) -- leading zero
set NewName to TheName & Divider & Counter & "." & TheExtension
end repeat
end tell
return NewName
end GetUniqueName
to EditItems of SomeItems given Title:TheTitle, Prompt:ThePrompt
displays a dialog for multiple item edit (note that a return is used between each edit item)
for each of the items in SomeItems, a line containing it's text is placed in the edit box
the number of items returned are padded or truncated to match the number of items in SomeItems
parameters - SomeItems [list]: a list of text items to edit
TheTitle [boolean/text]: use a default or the given dialog title
ThePrompt [boolean/text]: use a default or the given prompt text
returns [list]: a list of the edited items, or {} if error
set {TheItems, TheInput, TheCount} to {{}, {}, (count SomeItems)}
if TheCount is less than 1 then return {} -- error
if ThePrompt is in {true, false} then -- "with" or "without" Prompt
if ThePrompt then
set ThePrompt to "Edit the following items:" & return -- default
else
set ThePrompt to ""
end if
else -- fix up the given prompt a little
set ThePrompt to ThePrompt & return
end if
if TheTitle is in {true, false} then if TheTitle then -- "with" or "without" Title
set TheTitle to "Multiple Edit Dialog" -- default
else
set TheTitle to ""
end if
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set {SomeItems, AppleScript's text item delimiters} to {SomeItems as text, TempTID}
set TheInput to paragraphs of text returned of (display dialog ThePrompt with title TheTitle default answer SomeItems)
repeat with AnItem from 1 to TheCount -- pad/truncate entered items
try
set the end of TheItems to (item AnItem of TheInput)
on error
set the end of TheItems to ""
end try
end repeat
return TheItems
end EditItems
to replaceText of SomeText from OldItem to NewItem
replace all occurances of OldItem with NewItem
parameters - SomeText [text]: the text containing the item(s) to change
OldItem [text]: the item to be replaced
NewItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
set SomeText to SomeText as Unicode text -- TID's are case insensitive with Unicode text
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, OldItem}
set {ItemList, AppleScript's text item delimiters} to {text items of SomeText, NewItem}
set {SomeText, AppleScript's text item delimiters} to {ItemList as text, TempTID}
return SomeText
end replaceText
Message was edited by: gamebreakersWhen you use the open or adding folder items to handlers, you need to add the parameters for the file items passed to them.
I'll go ahead and post the applet/droplet version of my original script from the previous topic for reference:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #FFEE80;
overflow: auto;"
title="this text can be pasted into the Script Editor">
-- search and replace multiple items applet/droplet/folder action
-- the terms to replace - edit as needed
property EditableItems : {¬
"one", ¬
"two", ¬
"three", ¬
"four", ¬
"five", ¬
"six", ¬
"seven", ¬
"eight", ¬
"nine", ¬
"ten", ¬
"eleven", ¬
"twelve", ¬
"thirteen", ¬
"fourteen", ¬
"fifteen", ¬
"sixteen", ¬
"seventeen", ¬
"eighteen", ¬
"nineteen", ¬
"twenty"}
-- the folder for the output file(s) - change as needed
property TheFolder : (path to desktop)
property LastEditItems : EditableItems
on run
the applet/droplet was double-clicked
open (choose file with multiple selections allowed)
end run
on open TheItems
items were dropped onto the applet/droplet
parameters - TheItems [list]: a list of the items (aliases) dropped
returns nothing
repeat with AnItem in TheItems
ReplaceMultipleItems from AnItem
end repeat
end open
on adding folder items to this_folder after receiving these_items
folder action - items were added to a folder
parameters - this_folder [alias]: the folder added to
these_items [list]: a list if items (aliases) added
returns nothing
repeat with AnItem in these_items
ReplaceMultipleItems from AnItem
end repeat
end adding folder items to
to ReplaceMultipleItems from SomeFile
replace multiple text items in SomeFile
parameters - SomeFile [alias]: the file to replace items in
returns nothing
set TheName to (GetUniqueName for SomeFile from TheFolder) -- the name for the output file
set TheText to read SomeFile -- get the text to edit
set Originals to (choose from list EditableItems default items LastEditItems with prompt "Select the terms to replace:" with multiple selections allowed) -- the specific terms to replace
set LastEditItems to Originals
set Replacements to (EditItems of Originals with Title given Prompt:"Edit the following replacement terms:") -- the replacement terms
repeat with AnItem from 1 to count Originals
set TheText to (ReplaceText of TheText from (item AnItem of Originals) to (item AnItem of Replacements))
end repeat
try -- write a new output file
tell application "Finder" to make new file at TheFolder with properties {name:TheName}
set OpenFile to open for access (result as alias) with write permission
write TheText to OpenFile starting at eof
close access OpenFile
on error errmess
try
log errmess
close access OpenFile
end try
end try
end ReplaceMultipleItems
to GetUniqueName for SomeFile from SomeFolder
check if SomeFile exists in SomeFolder, creating a new unique name if needed
parameters - SomeFile [mixed]: a source file path
SomeFolder [mixed]: a folder to check
returns [text]: a unique file name and extension
set {Counter, Divider} to {"00", "_"}
-- get the name and extension
set {name:TheName, name extension:TheExtension} to info for file (SomeFile as text)
if TheExtension is in {missing value, ""} then
set TheExtension to ""
else
set TheExtension to "." & TheExtension
end if
set {NewName, TheExtension} to {TheName, (ChangeCase of TheExtension to "upper")}
set TheName to text 1 thru -((count TheExtension) + 1) of TheName
tell application "System Events" to tell (get name of files of folder (SomeFolder as text))
repeat while it contains NewName
set Counter to text 2 thru -1 of ((100 + Counter + 1) as text) -- leading zero
set NewName to TheName & Divider & Counter & TheExtension
end repeat
end tell
return NewName
end GetUniqueName
to EditItems of SomeItems given Title:TheTitle, Prompt:ThePrompt
displays a dialog for multiple item edit (note that a return is used between each edit item)
for each of the items in SomeItems, a line containing it's text is placed in the edit box
the number of items returned are padded or truncated to match the number of items in SomeItems
parameters - SomeItems [list]: a list of text items to edit
TheTitle [boolean/text]: use a default or the given dialog title
ThePrompt [boolean/text]: use a default or the given prompt text
returns [list]: a list of the edited items, or {} if error
set {TheItems, TheInput, TheCount} to {{}, {}, (count SomeItems)}
if TheCount is less than 1 then return {} -- error
if ThePrompt is in {true, false} then -- "with" or "without" Prompt
if ThePrompt then
set ThePrompt to "Edit the following items:" & return -- default
else
set ThePrompt to ""
end if
else -- fix up the given prompt a little
set ThePrompt to ThePrompt & return
end if
if TheTitle is in {true, false} then if TheTitle then -- "with" or "without" Title
set TheTitle to "Multiple Edit Dialog" -- default
else
set TheTitle to ""
end if
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set {SomeItems, AppleScript's text item delimiters} to {SomeItems as text, TempTID}
set TheInput to paragraphs of text returned of (display dialog ThePrompt with title TheTitle default answer SomeItems)
repeat with AnItem from 1 to TheCount -- pad/truncate entered items
try
set the end of TheItems to (item AnItem of TheInput)
on error
set the end of TheItems to ""
end try
end repeat
return TheItems
end EditItems
to ReplaceText of SomeText from OldItem to NewItem
replace all occurances of OldItem with NewItem
parameters - SomeText [text]: the text containing the item(s) to change
OldItem [text]: the item to be replaced
NewItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
set SomeText to SomeText as text
if SomeText contains OldItem then
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, OldItem}
try
set {ItemList, AppleScript's text item delimiters} to {text items of SomeText, NewItem}
set {SomeText, AppleScript's text item delimiters} to {ItemList as text, TempTID}
on error ErrorMessage number ErrorNumber -- oops
set AppleScript's text item delimiters to TempTID
error ErrorMessage number ErrorNumber
end try
end if
return SomeText
end ReplaceText
to ChangeCase of SomeText to CaseType
changes the case or capitalization of SomeText to the specified CaseType using Python
parameters - SomeText [text]: the text to change
CaseType [text]: the type of case desired:
"upper" = all uppercase text
"lower" = all lowercase text
"title" = uppercase character at start of each word, otherwise lowercase
"capitalize" = capitalize the first character of the text, otherwise lowercase
returns [text]: the changed text
set SomeText to SomeText as text
if CaseType is not in {"upper", "lower", "title", "capitalize"} then return SomeText
return (do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8')." & CaseType & "().encode('utf8')\" " & quoted form of SomeText)
end ChangeCase
</pre>
Edit: how does the choose from list dialog handle those big strings? I'm guessing not very well - is that why you avoided using them?
Message was edited by: red_menace
Maybe you are looking for
-
All of my files in the cloud are gone!!!
I was working on a project for a client just now and all of a sudden I get a notification from the Creative Cloud Connection that ALL of my files have been removed! I did nothing to trigger this. Now I cannot even see anything except my root folders
-
when I receive a email and I click on a link to open it in my I receive one window with the Google start page and another goes to the link that I clicked on. Is there a way to fix this so it only goes to the link that I click on instead of opening 2
-
Error 0210: stuck key 2b - t61 thinkpad + windows 7 32 bit
When ever I switch on the system i get this message error 0210: stuck key 2b". If I press esc key then it boots to the os windows 7 and also after booting up, if I open any ms word doc, the # key gets pressed automatically and I could see continous #
-
Too Many Snapshots - Only Need One
We have a web db server that we reset every night to a single snapshot, and it never changes. Vmware server creates a snapshot vmdk file every day though, and it fills up the disk. The host is windows 2003 x64 and the guest is the same. Can we delete
-
How do I set up Express box as addition to existing WIFI router?
Used to be able to do this when setting up the Express box, as I did years ago at home. But there's no option in the install process to enable this - which renders the product pretty useless. Any ideas? Cheers Neil