Find and Replace script for textWrangler - scripting

I'm trying to make a script that will find and replace some xml structure.
I've made it all flat, no spaces, no return.
So far I've made :
tell application "TextWrangler"
replace text "<key>amenity</key><string>drinking_water</string>" using text "<key>ico</key>
<string>NPpotableGPS30</string>"
end tell
The script editor says :
Error in TextWrangler : text "<key>amenity</key><string>drinking_water</string>" don't have the message « replace ».
This is my first script so I'm probably doing something wrong, but what ?

The key "text" seems to be misplaced. The following appears to correctly work (the sequence from searching onwards being optional for defining the document to process, according to actual working situation):
tell application "TextWrangler"
replace "<key>amenity</key><string>drinking_water</string>" using "<key>ico</key><string>NPpotableGPS30</string>" searching in text 1 of text document "..." options {search mode:grep, starting at top:true}
end tell

Related

Select line after finding keyword

I wanted to make a piece of code that selects the line in a text file when it finds the keyword that it's searching for. I have no clue what to actually do, what I searched up didn't help, was outdated, or for another language. I would need this code for vb.net. Thank you.
An example of what I mean.
Let's say we wanna search for: SO11
And there's other lines.
(1) : HJ6
(2) : 46J
(3) : SO11
(4) : NTE
(5) : 4UJ
And the searched line is in line 3. I want it to select line 3 and have it dimmed into a string so I can use it for future things.
Try breaking you question up into smaller chunks. You might be thinking to broadly.
For example:
Read Text File
While reading text file If file contains SO11 then save that line to variable.(Looping through that file.)
Do stuff with that variable.
Give that a try and let us know how it goes.

How do you get Notepad++ to treat # (hashtag) like a comment?

I have an SQL export file from my server with comments. The line comment operator used was the hashtag #. Notepad++ does not treat this like a commented out line, as in, the color does not change and any words such as like and while are changed to bold blue.
When you run the script on the server to install the SQL, it runs fine, the comments are treated as they should be. How do you tell NPP that the # operator is supposed to comment out the line? Both show the color and have Ctrl-k add a # in front of the line.
Note: I added commentLine="#" in the langs.xml file with no luck.
View -> User defined Dialogue -> Comment & number -> Comment Line
There you type in "#"
Before this you need to define a new language in the upper buttons.
What means, that the whole rest of the syntax isn't highlighted anymore.
But you could define it that way, how you want to. So you have an individual Syntax Highlighting including the commenting via "#"

Intellij - Reformat Code - Insert whitespace between // and the comment-text?

I am working with another human being on project from that the professor expects to have uniform code-style. We have written large separate junks of code on our own, in which one has written single line comments without a white-space between the single-line-comment-token and the other one has inserted a white-space. We are working with IntelliJ and have failed to find an option to enable the Reformat Code function, to insert a white-space.
TLDR:
Can you tell us how to convert comments from that to this in IntelliJ?
// This is a load bearing comment - don't dare to remove it
//This is a load bearing comment - don't dare to remove it!
You can do a global search and replace (ctrl-shift-r on windows with default keyboard layout, or Replace in Path under the Edit/Find menu).
Check the regular expression option and enter //(\S.*) as the text to find and // $1 as the replacement. Check the whole project option, and clear any file masks. You can single step through the replacements, or simply hit the All Files option.

Is there a tool for finding the Char code of a character?

I am trying to write a VB function to strip unwanted characters from a string. It is for generating a 'clean' url from data that has been inputted into a CMS. Someone has copied and pasted from a Word document and so there appears to be an mdash or ndash in the product title. This results in ─ appearing instead of -
I have tried a Replace(text, Chr(196), Chr(45)) but it isn't working so it can't be 196. Is there a tool or something where I can copy this character and paste it into the tool and it will tell me what char code it is?
Thanks.
You can make your program write out the Character Code using the finction Asc()
Response.write Asc("-") would write out
45
for example.
Try here or here. From 2nd link I can see that your char is alt150

vb.net VB 2010 Underscore and small rectangles in string outputs?

I've made some good progress with my first attempt at a program, but have hit another road block. I'm taking standard output (as a string) froma console CMD window (results of dsquery piped to dsget) and have found small rectangles in the output. I tried using Regex to clean the little bastards but it seems they are related to the _ (underscore), which I need to keep (to return 2000/NT logins). Odd thing is - when I copy the caharcter and paste it into VS2K10 Express it acts like a carrige return??
Any ideas on finding out what these little SOB's are -- and how to remove them?
Going to try using /U or /A CMD switch next..
The square is often just used whenever a character is not displayable. The character could very well be a CR. You can use a Regular Expression to just get normal characters or remove the CR LF characters using string.replace.
You mentioned that you are using the string.replace function, and I am wondering if you are replacing the wrong character or something like that. If all your trying to do is remove a carriage return I would skip the regular expressions and stick with the string.replace.
Something like this should work...
strInputString = strInputString.replace(chr(13), "")
If not could you post a line or two of code.
On a side note, this might give some other examples....
Character replacement in strings in VB.NET