w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
replace bytes with strings using Replace()
Assuming you are looking for the unicode char 0x00FF (ÿ) you just need to use the Unicode escape character `uxxxx. byte[] sttrings = new byte[pntrs[i + 1] - pntrs[i]]; stream.Position = pntrs[i]; stream.Read(sttrings, 0, sttrings.Length); Strs[i] = Encoding.GetEncoding("SHIFT-JIS").GetString(sttrings).Split('')[0].Replace("[u00FF]" , "/et"); If you really want to replace the byte values you may be able to use the String constructor that takes in a char[]. string replacementString = new String(new char[] {'[', '', (char)0xFF, ']'});

Categories : C#

How can I pass the Strings from an ArrayList to a method that takes in multiple Strings?
You can do something like this: ArrayList<String> list = new ArrayList<String>(); // Filling the list with strings... String[] stringArray = new String[list.size()]; list.toArray(stringArray); addStrings(stringArray); public addStrings(String... args) { // Do something with those Strings } Pass your strings in a primitive array. From the varargs documentation: The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments. All you'd need to do is derive a String[] from your List and then pass it to the addStrings(String... args) method. Credit to this question for the documentation link.

Categories : Android

MYSQL Replace array of strings with a randomly chosen array of strings
If you are looking for a quick and dirty solution, you could use something like this: UPDATE emails SET emails.address = CONCAT(SUBSTRING_INDEX(emails.address, '@', 1), '@', ELT(1+rand()*3, 'd.com', 'e.com', 'f.com', 'g.com')) WHERE SUBSTRING_INDEX(address, '@', -1) IN ('a.com', 'b.com', 'c.com') Please see fiddle here. Using SUBSTRING_INDEX(address, '@', -1) you can get the domain part of the address, and you can check if it is a.com, b.com, c.com, etc. Then you can update your email address, concatenating the first part of the address SUBSTRING_INDEX(address, '@', -1), the separator @, and a randomly chosen domain using ETL function: ELT(1+rand()*3, 'd.com', 'e.com', 'f.com', 'g.com') where 1+3 is the number of elements.

Categories : Mysql

How to replace a whitespace before number using Replace method?
That's a job for a positive lookahead assertion: String resultString = subjectString.replaceAll(" (?=\d)", " "); If you meant any kind of whitespace (including tabs, newlines, formfeeds etc.), use \s instead of the simple space I used here.

Categories : Java

str_replace - replace a set of strings with another set
You can give list of words in array as a parameter in str_ireplace, $str = str_ireplace(array("worda","wordb"),array("Worda","woRrdb"),$str); More beautifully, $searchWords = array("worda","wordb"); $replaceWords = array("Worda","woRrdb"); $str = str_ireplace($searchWords,$replaceWords,$str);

Categories : PHP

How to replace a string between two other strings
You need to escape literal dots in your regular expression, otherwise . will match any character except newlines. Something like this should work: $c = $c -replace 'StringResourceHelper.(w*?)ResourceString()', 'Strings.$1' Also, your code could be simplified a little, like this: $srch = 'StringResourceHelper.(w*?)ResourceString()' $repl = 'Strings.$1' Get-ChildItem . *.cs -Recurse | % { $filename = $_.FullName (Get-Content $filename) -replace $srch, $repl | Set-Content $filename -Encoding UTF8 }

Categories : Powershell

How to replace Æ to AE for all strings in my table?
You could always dump (export) the table contents, getting a create and insert command that you paste into a text editor, replace all Æ-s to AE, drop the table and run the exported script that wil re-create it with the changes you made.

Categories : PHP

sed - find text between 2 strings and use it for replace
Use sed -e 's/"[^"]*"/&, &/': $ cat 1 townValue.put("Aachen"); townValue.put("Aalen"); townValue.put("Ahlen"); townValue.put("Arnsberg"); townValue.put("Aschaffenburg"); townValue.put("Augsburg"); $ sed -e 's/"[^"]*"/&, &/' 1 townValue.put("Aachen", "Aachen"); townValue.put("Aalen", "Aalen"); townValue.put("Ahlen", "Ahlen"); townValue.put("Arnsberg", "Arnsberg"); townValue.put("Aschaffenburg", "Aschaffenburg"); townValue.put("Augsburg", "Augsburg"); According to sed(1): s/regexp/replacement/ Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to re

Categories : Unix

How to replace strings in StringFormat in WPF Binding
You can't do this via a StringFormat binding operation, as that doesn't support replacement, only composition of inputs. You really have two options - expose a new property on your VM that has the replaced value, and bind to that, or use an IValueConverter to handle the replacement. A value converter could look like: public class AddNewlineConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string original = Convert.ToString(value); return original.Replace(",", ", "); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplemnentedException(); } } You'd then use this in your binding. You could add a resou

Categories : Wpf

Replace many strings by their counterparts according to a mapping
This is one way: with(mapping, iso3[match(countries, country)]) # [1] USA ECU RUS RUS ECU # Levels: ECU RUS USA Wrap this in as.character to the result as a character vector.

Categories : R

How to replace several strings in a text file? c++
Because you open the original file on the second run of ModifyParameterIn and overwrite the output file. Hence, you first change is simply overwritten. You shouldn't open the file in the ModifyParametersIn function, but rather in main. This of course has the problem that the two strings you are trying to replace have to be in the correct order in the file, otherwise, one replacement will also fail. You could also work some magic to open the file you last wrote to in the function ModifyParametersIn an write it to a new file, leading to a bunch of new files, of which you only use the last one. But that's rather ugly.

Categories : C++

Replace all strings in the form ".get_x()"?
Replace matches of .get_(w+)() with .1. Note that depending on the tool you use you may need to use $1 for the replacement instead of 1. Obviously you can do something similar to replace the .set_x(), or you could do them both at once using the following regex: .[gs]et_(w+)()

Categories : Regex

Replace multiple strings in csv file
Hmm... this worked fine for me. I'm running python 2.7.3 try a minimal test case starting with file1.csv containing "123abc": def replace_all(text, dic): for i, j in dic.iteritems(): text = text.replace(i, j) return text f_dic = {'a':'d'} s_dic = {'1':'x'} with open('file1.csv','r') as f: text=f.read() with open('file2.csv','w') as w: text=replace_all(text,f_dic) text=replace_all(text,s_dic) print text w.write(text) After running, file2.csv contained x23dbc Perhaps my test case was too simple. How about you give us what you had in file1.csv, what you expected to see in file2.csv and what you actually saw in file2.csv.

Categories : Python

Replace substring with binary strings
The problem with casting to text and back to bytea is that it wouldn't work if the replacement strings involved quoted bytes in strings. Let's see with an example. (I'm setting bytea_output to hex to better see the text, otherwise it's all hex numbers) Initial query: with input(x) as (values (('0015Hello World0015Hello World'::bytea))) select replace(x::text, 'World', 'Jenny')::bytea from input; The result is fine: replace ---------------------------------------- 0015Hello Jenny0015Hello Jenny (1 row) But if trying with a modified version that wants to replace the character 0 by 1 with input(x) as (values (('0015Hello 0orld0015Hello 0orld'::bytea))) select replace(x::text, '0', '1')::bytea from input; The result is: repla

Categories : String

Dynamic Method Call In Python 2.7 using strings of method names
If you're calling a method on an object (including imported modules) you can use: getattr(obj, t[i])(*args) If you need to call a function in the current module getattr(sys.modules[__name__], t[i])(*args) where args is a list or tuple of arguments to send, or you can just list them out in the call as you would any other function. Since you are in a method trying to call another method on that same object, use the first one with self in place of obj getattr takes an object and a string, and does an attribute lookup in the object, returning the attribute if it exists. obj.x and getattr(obj, 'x') achieve the same result. There are also the setattr, hasattr, and delattr functions if you want to look further into this kind of reflection. A completely alternative approach: After not

Categories : Python

How to replace strings resources with Android Gradle
In your "src" folder, create "flavor1" and "flavor2" folders with the same hierarchy as your "main" folder. If you have strings.xml in your main/res/values, you can do it in flavor1/res/values as well and have the replacement values in there. It may show errors in the IDE but it should still build and run.

Categories : Android

Replace multiple strings with a single sentence
You're overwriting strReplaced in each loop run. It seems like you want this instead: for(i=0; i<=4; i++) { desc = desc.Replace(BadCharacters[i], GoodCharacters[i]); } Label1.Text = desc;

Categories : C#

Hadoop Pig - Replace strings in a relation with their corresponding values in a map
The first issue with this is that in a map the key must be a quoted string. So you can't use a schema value to access the map. E.G. This will not work. C: {foo: chararray, M: [value:chararray]} D = FOREACH C GENERATE M#foo ; The solution that comes to mind is to FLATTEN conversations_grouped. Then do a join between conversations_grouped and line_map on the L[0-9]+ tag. You'll probably want to project out some of the extra fields (like the L[0-9]+ tag after the join) to make the next step faster. After that you'll have to regroup the data, and massage it into the correct format. This won't work unless each bag has it's own unique ID for the regrouping, but if each of the L[0-9]+ tags appear in only one bag (conversation) you can use this to create a unique id. -- A is dumped conversati

Categories : Apache

How Replace String[] Constants with Strings[] from SQLITE
You cannot do this : String [] paths = null; and then this : paths[i] = cursor.getString(0).toString(); // i is 0 initially This will throw ArrayIndexOutOfBoundsException. You can use a List<String> for this purpose instead of String[] . Add each element to the List<String> using its add() method. List<String> pathList = new ArrayList<String>(); pathList.add(cursor.getString(0)); Then return an array from the method as : return pathList.toArray(new String[pathList.size()]);

Categories : Java

replace dictionary keys (strings) in Python
name_mapping = { 'voornaam': 'first_name', ... } dic = your_dict # Can't iterate over collection being modified, # so change the iterable being iterated. for old, new in name_mapping.iteritems(): value = dic.get(old, None) if value is None: continue dic[new] = value del dic[old]

Categories : Python

Replace strings with double quotes in a XML file
I don't understand why you said "As the line sizes are huge, I have no choice but to use awk". AFAIK sed is no more limited on line length than awk is and since this is a simple substitution on a single line, sed is the better choice of tool: $ cat file Pattern="abc" $ sed -r 's/(Pattern=")[^"]+/1def/' file Pattern="def" If the pattern occurs multiple times on the line, add a "g" to the end of the line. Since you mention in your comment being stuck with a sed that can't handle long lines, let's assume you can't install GNU tools so you'll need a non-GNU awk solution like this: $ awk '{sub(/Pattern="[^"]+/,"Pattern="def")}1' file Pattern="def" If you LITERALLY mean you only want to replace Pattern="abc" then just do: $ awk '{sub(/Pattern="abc"/,"Pattern="def"")}1' file Pattern="def"

Categories : Regex

Efficient Way to Replace Custom Strings with Numbers in MATLAB
You were on the right track. After defining: serial_numbers = {'serial1'; 'serial1'; 's2'; 'serial31010'} This seems to be simple: [~,~,new_serial_numbers ] = unique(serial_numbers,'stable') will give: new_serial_numbers = 1 1 2 3 Don't know about the performance of the 'unique' function

Categories : Matlab

mysql join, replace for comma separated strings
I would also suggest normalising the design of the database. However failing that it is possible a couple of ways. For example something like this (not tested):- SELECT a.first_name, a.last_name, GROUP_CONCAT(DISTINCT c.name) FROM signup_protect a INNER JOIN user_results b ON b.uid = a.uid INNER JOIN q_values c ON FIND_IN_SET(c.id, REPLACE(b.value_ids, ':', ',')) > 0 GROUP BY a.first_name, a.last_name Don't expect it to be quick! As prompted by Rocket Hazmat it is best to GROUP BY a real unique value (names might not be unique) hence something like this:- SELECT a.uid, a.first_name, a.last_name, GROUP_CONCAT(DISTINCT c.name) FROM signup_protect a INNER JOIN user_results b ON b.uid = a.uid INNER JOIN q_values c ON FIND_IN_SET(c.id, REPLACE(b.value_ids, ':', ',')) > 0 GROUP BY

Categories : Mysql

python using a dictionary to replace characters in a list of strings
progression is a list. To access content from it, you need to use the index value, which is an integer, and not a string, hence the error. You probably want: for i, j in enumerate(words): words[i] = clues.get(j) What enumerate does is loops through the list of words, where i is the index value and j is the content. .get() is similar to dict['key'], but if the key is not found it returns None instead of raising an error. Then words[i] modifies the list with the index number of the word

Categories : Python

replace strings with double quotes in a text file
Code for GNU sed: $echo class="EmployeeDataModel" |sed s/EmployeeDataModel/EmployeeData/g class="EmployeeData" And perl also works: $echo class="EmployeeDataModel" |perl -pi -w -e s/EmployeeDataModel/EmployeeData/g; class="EmployeeData"

Categories : Regex

Python: Replace non ascii characters in a list of strings
>>> mylist = ["apple", "samsung", "toshiba", "Don’t know", "Can’t recall"] >>> [item.replace('xe2x80x99',"'") for item in mylist] ['apple', 'samsung', 'toshiba', "Don't know", "Can't recall"] If all the items are already unicode: >>> mylist = [u"apple", u"samsung", u"toshiba", u"Don’t know", u"Can’t recall"] >>> [item.replace(u'’',u"'") for item in mylist] [u'apple', u'samsung', u'toshiba', u"Don't know", u"Can't recall"]

Categories : Python

Code to replace opening and closing " with different strings (UVa 272 - Tex Quotes) not working
Unfortunately your code do not even pass sample testcase! Anyways, just put this line, int nDoubleQuotes = 0; out of the while( getline( cin , inputString ) ) loop, the reason you need to do it is, In the input file a quotation mark (") can start in one line and can end in any other following line, as the sample test case showed in the problem statement: The programming contestant replied: "I must disagree. #quote start on this line To `C' or not to `C', that is The Question!" #quote ends on this If you initialize quote counter variable on every line then you are assuming, quote marker start and end on the same line, which is wrong.

Categories : C++

replace strings with lines from another text file by matching patterns
Use awk command like this: awk 'NR==FNR {a[$1]=$2;next} { split($1, b, ":"); if (b[1] in a) print a[b[1]] ":" b[2], $2; else print $0; }' keyFile.txt temp.txt

Categories : Regex

How do I replace all strings found with a regular expression with itself concatenated with another string?
You don't need regex for that, just find the string you want with a buid-in function and concatenate with what you want. For a more general search/replace you can do this: string pattern = @"(?>w+\)+w+.xml"; string replacement = "new_root\$0"; Regex rgx = new Regex(pattern); string result = rgx.Replace(input, replacement);

Categories : C#

Find and replace comma-separated strings to Cassandra list format in VIM
Try this :%s/v(".*)@<=s*([^,"]+)s*(.*")@=/'2'/g :%s/"/"[ :%s/"[@!/]" Or all at once :%s/v(".*)@<=s*([^,"]+)s*(.*")@=/'2'/ge | %s/"/"[/e | %s/"[@!/]" This works on the example. This will not work if there more than one pair of quotes on the line. Explanation :%s/v(".*)@<=s*([^,"]+)s*(.*")@=/'2'/g This looks for a string that has a quote before and after it with lookaheads and lookbehinds. Then we capture everything that isn't a comma or a quote and replace it with the captured part in single quotes. This throws out any leading or trailing spaces. :%s/"/"[ This should be self explanatory if you have used :s before :%s/"[@!/]" This uses a negative lookahead to find the first quote that isn't followed by a left bracket and replaces it with a right bracket and a quote.

Categories : Regex

Search and replace strings in Java source files using Emacs and regular expressions
If you must do this using native emacs: Word boundaries are a reasonable search boundary. The Matcher class is a Java construct. If you were writing code to do the search and replace. Since you are doing this completely in emacs, it wouldn't apply. There is a caveat that these variables can't be used from multiple source files or you will mess things up. I wouldn't do this with raw emacs though. I'd use an IDE refactoring tool. Emacs even has a Java Refactoring that you can install. Using a refactoring tool, the tool understands the syntax and will be more specific than a regular expression.

Categories : Regex

How to replace .live() method with .on() method
Actually, you're missing the # in the id selector. $("#the_news_feed").on("click", "load_more_feed", function() must be $("#the_news_feed").on("click", "#load_more_feed", function() assuming #the_news_feed is the parent of #load_more_feed. EDIT : From your code, you're appending this #loadmore button after #the_news_feed, so this obviously will not work. Try changing it to this : $(document).on("click", "#load_more_feed", function() This will bind the click to the document, which will always exist. Alternatively, you could bind it to #load_more_feed closest static parent, like an element which exists when you load your page and not dynamically created.

Categories : Javascript

Return two Strings from method
In Java, you concatenate Strings with the + operator. Proper syntax for what you were trying to do looks like this: System.out.println("Democrats: " + Democrats); System.out.println("Republicans: " + Republicans); A return statement is only used when you want to return some object or value to a method that called your current method. It is not appropriate in this place since you're only passing a value to another method (println()). ALSO, you need to fix your getTallies() method. Make it return void instead of double since you aren't returning anything.

Categories : Java

Batch file to filter strings from text and replace... but in a single batch instead of multiple?
for /f "tokens=1 delims=# " %%a in (id.txt) do ( >>trials.txt echo(#%%a >>test_out.txt echo(Give trial:%%a ) Don't really know whether you need trials.txt or whether id.txt contains ONLY lines matching #nnn ...

Categories : Windows

How to get object method (object."something"), where method name comes from a list of strings ("something" is a string)?
For form controls, use the Controls method. This can be used on its own, or inside a loop: for i=1 to 5 frmUserForm.Controls("Label" & i).Enabled = True next i Does that make sense?

Categories : String

How to organize strings through a sort method
A NumberFormatException is thrown when you attempt to parse some text into a number, but the text is not a number, such as in your example: "d". You mentioned that you had this code working with integers, then converted it to work with letters. Most likely, you forgot to take out the code (which you haven't shown here) that parses the input into a number. You should take out that code and accept the user's input as text as originally inputted.

Categories : Java

How do I calling an object's method using strings?
You should store the object in a hashmap with key = name and value = object, then use b (name) to retrieve the right object from the hashmap. I'm still not sure what do you want to do with the second input, by my guess is that this answer covers that as well. h = Hash.new() h["trance x3"] = trance h["giro"] = giro ... puts "Which bike do you want information on?" b = gets() b.chomp! user_bike = h[b] puts "What information are you looking for?" i = gets() i.chomp! user_bike.send(i)

Categories : Ruby

How to organize strings through a sort method?
You can easily do this with Collections.sort. See if the String's default compareTo method works for you. If it does, it'll sort that way. Just do this: List<String> alphabet = new ArrayList<String>(); //populate with Strings Collections.sort(alphabet); And then your alphabet will be mutated to be in abc order. As for your actual error, I can't figure out where that line is occurring (if you tell us where the stack trace points to, I could). But it looks like you've got some code that is trying to convert a String into a Number, but the String doesn't represent a number. Specifically, somewhere you're trying to turn "d" into a number.

Categories : Java

Best method for Concatenating N strings of length L_N?
sprintf returns the number of characters 'printed' (added to the string), so you can start with an index of 0 and then simply add the result of each next sprintf (string + index, ...

Categories : C

Replace a method using Roslyn
Due to the fact that Roslyn SyntaxNode objects are immutable, every time you call "ReplaceNode", you get a whole new tree back. The normal way to solve this problem is to add a SyntaxAnnotation to each node you want to replace. This is a stable marker that will be preserved through tree transformations as long as the node itself isn't replaced. Alternatively, when making many changes to a file like this, you could look at implementing a SyntaxRewriter, instead of just calling ReplaceNode a bunch of times. SyntaxRewriter will visit the tree bottom-up, so the node passed to the method will always be from the original SyntaxTree. However, make sure you first call base.Visit() in any method you override and use the result so that you have the updated version of any nodes that are descendan

Categories : C#



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