w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Changing the start number of an ordered list dependent of a query string
Solved it! My code is below - it's very specific to my example (it includes the {?pageresults?} macro from Kentico), but you should be able to reverse engineer a solution if you're coming up against a similar issue. Requires jQuery, for neatness: <script> $(document).ready(function() { var x=({?pagesearchresults?}-1)+"1" if (x<"1"){x="1";} $('#search_results').attr( 'start', x ); }); </script> <h3>Search Results</h3> <ol start="" id="search_results">

Categories : Javascript

node.js how to insert string to beginning of file but not replace the original text?
Open the file in append mode using the a+ flag var fd = fs.openSync('file', 'a+'); Or use a positional write. To be able to append to end of file, you need the size of the file. var stats = fs.statSync('file'); fs.write(fd, buf, 0, buf.length, stats.size); Write to the beginning of a file: fs.write(fd, buf, 0, buf.length, 0); EDIT: I guess there isn't a single method call to that. But you can copy the contents of the file, write new data, and append the copied data. var data = fs.readFileSync(file); //read existing contents into data var fd = fs.openSync(file, 'w+'); var buffer = new Buffer('New text'); fs.writeSync(fd, buffer, 0, buffer.length); //write new data fs.writeSync(fd, data, 0, data.length); //append old data fs.close(fd);

Categories : Node Js

Delete all spaces at the beginning of each line in a variable that contains a large string
The variable holds a string that contains line break characters, is that? if it is, try setting the property Multiline of the RegExp to true. From: http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/ (You could also split each line into an array and do the Regex on a loop on each)

Categories : Vbscript

Find column values that are a start string of given string.
Simple turn around the "Like" operator: SELECT * FROM urls WHERE "www.example.com/foo/bar/baz/here.html" LIKE CONCAT(url, "%"); http://sqlfiddle.com/#!2/ef6ee/1

Categories : Mysql

Adding "" to a String Python | How to insert a "" before each paren in a string?
>>> import re >>> strs = "(hi)" >>> re.sub(r'([()])',r'\g<0>',strs) '\(hi\)' "" is invalid because you're escaping the closing quote here, so python will raise EOF error. So you must escape the first using another : >>> "\" '\' >>> "" File "<ipython-input-23-bdc6fd40f381>", line 1 "" ^ SyntaxError: EOL while scanning string literal >>>

Categories : Python

Batch File to Move Files with Same Beginning String to a Folder with That String Name
I'm not entirely sure what you want, but I think this will work: setlocal enabledelayedexpansion cd C:...[path to folder] set /a count=0 for /r "delims=-" %%a in (*) do ( set /a count=!count!+1 for /l %%z in (1,1,!count!) do ( if %%a equ !%%z! ( move %%a C:...[out put folder collection]!%%z!\%%a%%b ) else ( set !count!=%%a) ) ) Output Folder Collection > 1 >> name - 1.txt >> name - 2.txt >> name - 3.txt > 2 >> name - 1.txt >> name - 2.txt >> name - 3.txt > 3 >> name - 1.txt >> name - 2.txt >> name - 3.txt I'm pretty sure that will work. Haven't tested it, so if you find or get any errors tell me. Note: This will only accept one "-" in the file name. Having more then one means it wil

Categories : Batch File

Bash: loop through file line by line, find specific string and append to each subsequent line until same string is found
If I have your requirements right, this little awk program will work: awk '/^AB1/{ab1=$0;next}/^AB2/{print $0, ab1}' That will do nothing with any line which doesn't start with AB1 or AB2 and it fails to check for equality of the 12-character string following the AB1/AB2. I couldn't tell if you require that check.

Categories : Regex

while trying to reverse string in javascript, getting NaN in the beginning of the reversed string
It would be easier to just split the string into an array of the parts, and then javascript has a reverse() method to reverse the order of the array, and then you can join it back together again: var input = "string to be reversed"; var output = input.split('').reverse().join(''); FIDDLE

Categories : Javascript

The string constant beginning with "')" does not have an ending string delimiter
There is a missing ' - this is better: insert into employee values ('&v_emp_id','&v_emp_name','&v_address','&v_tel_no','&v_dob','&v_stor_id'); ^

Categories : SQL

May I define two Default string in values directory?
You need to Localizing with Resources. Where you can easily do you task. Below content Reference : Supporting Different Languages To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time. Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example: MyProject/ res/ values/ strings.xml values-es/ strings.xml values-fr/ strings

Categories : Android

How to insert text at the beginning and ending of a specified line?
Try the following snippet : sed '2s/.*/[text_insert] & [text_insert2]/' file.txt & have a special meaning: it's the matching part from the left part of the substitution s/// Ex : $ cat file.txt a b c $ sed '2s/.*/[text_insert] & [text_insert2]/' file.txt a [text_insert] b [text_insert2] c

Categories : Bash

How can I quickly convert to a list of lists, insert a string at the start of each element?
Maybe something like this: >>> import numpy as np >>> data = [1,2,3] >>> a = np.empty([len(data),2], dtype=object) >>> a array([[None, None], [None, None], [None, None]], dtype=object) >>> a[:,0]='a' >>> a array([[a, None], [a, None], [a, None]], dtype=object) >>> a[:,1]=data >>> a array([[a, 1], [a, 2], [a, 3]], dtype=object) >>> data2=np.array([[1,2],[3,4],[5,6]]) >>> data2 array([[1, 2], [3, 4], [5, 6]]) >>> b = np.empty([len(data2),3],dtype=object) >>> b array([[None, None, None], [None, None, None], [None, None, None]], dtype=object) >>> b[:,0]='a' >>> b array([[a, None, None], [a, No

Categories : Python

jQuery: how do I insert html into a string, both before the string (the easy part) and WITHIN the string?
You need to insert the start tag at the same time as the end tag. var index = $('.entry-title').html().indexOf('...'); $('.entry-title').html('<span class="category">' + $('.entry-title').html().substring(0, index) + '</span>' + $('.entry-title').html().substring(index));

Categories : Jquery

Whenever I type colon in insert mode it moves my text to the very beginning of line
Adding a colon to the end of a token is causing vim to interpret it as a jump label for C-indenting purposes. :set cino+=L0 should cause it to stay in the current column. Also, doesn't the JSON syntax allow you to quote the thing that precedes the colon? That should prevent vim from thinking it's a label too. var combo = new Ext.form.ComboBox({ "typeAhead": "foo" // this isn't a jump label });

Categories : Vim

What's the advantage of having multi-line & single-line string literals in python?
The advantage of having to be explicit about creating a multi-line string literal is probably best demonstrated with an example: with open("filename.ext) as f: for line in f: print(line.upper()) Of course, any decent syntax-highlighting editor will catch that, but: It isn't always the case that you're using a syntax-highlighting editor Python has no control over what editor you are using. Two of Python's design principles are that errors should never pass silently, and explicit is better than implicit. Outside docstrings, multi-line strings are rarely used in Python, so the example above is much more likely to occur (everyone mistypes sometimes) than the case where you want a multi-line string, but forgot to explicitly say so by triple-quoting. It's similar to Pyth

Categories : Python

Can this be done without an eval? (note: expression does come from a string)
I'm confused. You shouldn't ever have to use eval() for something like this, when you can easily set $value to the real boolean value such as: $value = (convertToBytes("1024K") >= 102400);

Categories : PHP

Read a multi-line string as one line in Python
Assuming you are using windows if you do a print in the file you will see '123 ABCDEF ST APT 456 ' of course this assumes that you did a read statement instead of readlines so there are a number of ways to do this myList = [item for item in myFile.split(' ')] newString = ' '.join(myList)

Categories : Python

grep for a string in a line if the previous line doesn't contain a specific string
I think you're better off using an actual programming language, even a simple one like Bash or AWK or sed. For example, using Bash: ( previous_line_matched= while IFS= read -r line ; do if [[ ! "$previous_line_matched" && "$line" == *xyz* ]] ; then echo "$line" fi if [[ "$line" == *jkl* ]] ; then previous_line_matched=1 else previous_line_matched= fi done < input_file ) Or, more tersely, using Perl: perl -ne 'print if m/xyz/ && ! $skip; $skip = m/jkl/' < input_file

Categories : Unix

Python re.sub() beginning-of-line anchoring
You forgot to enable multiline mode. re.sub("^and", "AND", s, flags=re.M) re.M re.MULTILINE When specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline); and the pattern character '$' matches at the end of the string and at the end of each line (immediately preceding each newline). By default, '^' matches only at the beginning of the string, and '$' only at the end of the string and immediately before the newline (if any) at the end of the string. source The flags argument isn't available for python older than 2.7; so in those cases you can set it directly in the regular expression like so: re.sub("(?m)^and", "AND", s)

Categories : Python

converting a string to another only by insert in python
It is possible to convert the first one to the second, but not the third. E.g.: words = sentence.split() words.insert("school", 3) words.insert("bus", 6) sentence = ' '.join(words) It is not possible to convert the second into any of the other strings by insertions only, since the "I" needs to be replaced by a "you".

Categories : Python

Python: Insert string (colon) in between HEX
The answer to your question is here: Pythonic way to insert every 2 elements in a string You could also use a step i.e. str[::x] to loop over every 2 characters to achieve this result. myStr = 'AABBCCDDEEFF112233' print ':'.join(myStr[i:i+2] for i in range(0, len(myStr), 2))

Categories : Python

Does multiple #define of the same string use the same constant string?
The compiler does something called string interning. It is not a necessary operation so if your code relies on test being at the same address then you may have some problems. For the most part yes, it will try to reuse strings that are the same and just make them all point to the same string (in read only memory).

Categories : C++

- The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (String, String, String, String, String,
PreparedStatement.setString() is not a variable arity method; it doesn't take variable no. of arguments. Each placeholder(?) must be set individualy using stmt.setString(1, "Charlie Sheen"); stmt.setString(2, "help@glomindz.com"); and so on. Using Spring's JdbcTemplate jdbcTemplate.update("INSERT INTO spl_user_master(name,email,mobile,password,role,status,last_update)VALUES(?,?,?,?,?,?,?)", new Object[] { "Charlie Sheen","help@glomindz.com","9654087107","cbf51a71a11d7ec348b0d7e9b2f0055f","admin","3","null"});

Categories : Java

Python - Remove Last Line From String
You can remove the last line of a string like this: def remove_last_line_from_string(s): return s[:s.rfind(' ')] string = "String with some newlines to answer on StackOverflow. This line gets removed" print string string = remove_last_line_from_string(string) print ' '+string The output will be: >>> String with some newlines to answer on StackOverflow. This line gets removed String with some newlines to answer on StackOverflow. >>>

Categories : Python

Escape (Insert backslash) before brackets in a Python string
You've already found the most Pythonic way, regex provides a not so readable solution: >>> import re >>> s = u'LastName FirstName (Department / Subdepartment)' >>> print re.sub(r'([()])', r'\1', s) LastName FirstName (Department / Subdepartment)

Categories : Python

Insert negative ASCII character in python string
The real answer is that you have been relying on non standard behavior in your C code (one of the language lawyers can butt in and tell you if it's truly undefined or not). You need to look into how to properly support non ASCII, multibyte character sets in python rather than just trying to duplicate your incorrect C code. There are plenty of resources that will help with correct "i18n" of an app.

Categories : Python

Empty string for system property for wifi.interface on Samsung Galaxy Note 2 and Tab 2
I think "wifi.interface" property is not set in JB of note 2. This is set in other devices variants like S2 etc., This need to be set to "wlan0" in one of the device specific rc file.

Categories : Android

how to get a string from split line and compare in python
You can use str.rsplit: >>> strs = 'Jan 31 00:57:07 2012 GMT' str.rstrip will return a list like this: >>> strs.rsplit(None,2) ['Jan 31 00:57:07', '2012', 'GMT'] Now we need the second item: >>> year = strs.rsplit(None,2)[1] >>> year '2012' >>> if 2010 <= int(year) <= 2013: #apply int() to get the integer value ... #do something ...

Categories : Python

How to minimize string-appending to one line in Python?
If you need to find items that starts with 'A', you can use list comprehension or filter: >>> l = ["Aaaa", "test", "A1", "1"] >>> [item for item in l if item.startswith('A')] ['Aaaa', 'A1'] >>> l = ["Aaaa", "test", "A1", "1"] >>> filter(lambda item: item.startswith('A'), l) ['Aaaa', 'A1'] If you want to add 'A' to items in the list that dont't start with 'A', you can use list comprehension or map: >>> l = ["Aaaa", "test", "A1", "1"] >>> ['A' + item if not item.startswith('A') else item for item in l] ['Aaaa', 'Atest', 'A1', 'A1'] >>> map(lambda item: 'A' + item if not item.startswith('A') else item, l) ['Aaaa', 'Atest', 'A1', 'A1'] FYI, you'll get a new list in both cases. If you want to the modify list in-place, you can

Categories : Python

How can I print variable and string on same line in Python?
Use , to separate strings and variables while printing: print "If there was a birth every 7 seconds, there would be: ",births,"births" , in print statement separtes the items by a single space: >>> print "foo","bar","spam" foo bar spam or better use string formatting: print "If there was a birth every 7 seconds, there would be: {} births".format(births) String formatting is much more powerful and allows you to do some other things as well, like : padding, fill, alignment,width, set precision etc >>> print "{:d} {:03d} {:>20f}".format(1,2,1.1) 1 002 1.100000 ^^^ 0's padded to 2 Demo: >>> births = 4 >>> print "If there was a birth every 7 seconds, there would be: ",births,"births" If there was a birth every 7 seconds, there

Categories : Python

Getting the first string after a symbol in a line of text python
Just split on @ and then split whatever comes after it. before_at, after_at = line.split('@') K = int(after_at.split()[0]) For extra efficiency, if you only want the first thing after the @, do after_at.split(None, 1) -- that only splits once (on whitespace). This will raise an exception when there's more than one @, which may or may not be what you want.

Categories : Python

Javascript to match string with pattern and insert some text in the matched string
This regex based solution should work for you: str = 'blah blah text blah <a href="/abcblah/blah">some random text</a> text blah random'; repl = str.replace(/(href=['"](?!https?:))/?/g, "$1http://www.rooturl.com/"); console.log(repl); Live Demo: http://ideone.com/G5F0vF

Categories : Javascript

Python: Invalid Syntax on line 1 (file )
Replace input() with raw_input(): print("Please enter a quote you would like to use: ") quote = str(raw_input()) Or even: quote = raw_input("Please enter a quote you would like to use: ")

Categories : Python

Incorrect syntax with a string that takes up more than 1 line Python
You need to use multi-line strings, or else parentheses, to wrap a string in Python source code. Since your string is already within parentheses, I'd use that fact. The interpreter will automatically join strings together if they appear next to each other within parens, so you can rewrite your code like this: given = raw_input("Is " + str(ans) + " your number?" "Enter 'h' to indicate the guess is too high. " "Enter 'l'to indicate the guess is too low. " "Enter 'b' to indicate that I guessed correctly") This is treated much as though there was a + between each of those strings. You could also write the plusses in yourself, but it's not necessary. And as I alluded to above, you could also do it with triple-quoted strings (''' or """).

Categories : Python

How to print string inside a parentheses in a line in Python?
You can use regex: >>> import re >>> s = "562: DEBUG, CIC, Parameter(Auto_Gain_ROI_Size) = 4" >>> t = "711: DEBUG, VSrc, Parameter(Auto_Contrast) = 0 " >>> myreg = re.compile(r'Parameter((.*?))') >>> print myreg.search(s).group(1) Auto_Gain_ROI_Size >>> print myreg.search(t).group(1) Auto_Contrast Or, without regex (albeit a bit more messier): >>> print s.split('Parameter(')[1].split(')')[0] Auto_Gain_ROI_Size >>> print t.split('Parameter(')[1].split(')')[0] Auto_Contrast

Categories : Python

String portion after variable in .write() being put on new line in Python
Looks like str(arch) has a trailing new line, you can remove that using str.strip or str.rstrip: strarch = str(arch).strip() #removes all types of white-space characters or: strarch = str(arch).rstrip(' ') #removes only trailing ' ' And you can also use string formatting here: strarch = str(arch).rstrip(' ') info.write("{}: {} {}".format("Arch Bits", strarch, "bits")) Note that there's no need of info.close(), with statement automatically closes the file for you.

Categories : Python

passing values string values to an object and recieving a string in return in ios
Check your brain using NSLog in the (IBAction)kickit:(UIButton *)sender function. I guess you didn't initialise brain. If this is not the case, you need to provide more code.

Categories : IOS

string manipulation : insert words at certain indexes in string, simultaneously
This is not exactly doing what you want, but consider this as an alternative solution what tries to achieve your goal via different means. I will suppose two different things, firstly, suppose there exists a List<String> words, which contains the words you want to replace. Then code will be: public String insertTags(final String input) { for (String word : words) { input.replace(word, "[start]" + word + "[end]"); } return input; } Second case, closer to your example but not using the indices, suppose there exists a Map<String, List<Integer>>, which contains the words and the indices to replaces them at in a list representation. Then code would be: public String insertTags(final String input) { for (Map.Entry<String, List<Integer>>

Categories : Java

Remove BR tag from the beginning and end of a string
There is no need to use regular expression for it you can simply use yourString.Replace("<br>", ""); This will remove all occurances of <br> from your string. EDIT: To keep the tag present in between the string, just use as follows- var regex = new Regex(Regex.Escape("<br>")); var newText = regex.Replace("<br>thestring<br>Iwant<br>", "<br>", 1); newText = newText.Substring(0, newText.LastIndexOf("<br>")); Response.Write(newText); This will remove only 1st and last occurance of <br> from your string.

Categories : C#

Is it possible to cut off the beginning of a string using regex?
I think this will work: var str = "/foo/bar/baz/hello/world/bla.html"; alert( str.replace( /^.*?(/[^/]*(?:/[^/]*)?)$/, "$1") ); This will allow for there being possibly only one last part (like, "foo/bar").

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.