w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to replace several characters on a single string to desired characters (java)?
public class TranslateChar { /** @param args */ public static void main(final String[] args) { final Map<Character, Character> mapCharCod = new HashMap<>(36); final Map<Character, Character> mapCharDecod = new HashMap<>(36); mapCharCod.put('A', 'Z'); mapCharCod.put('B', 'X'); mapCharCod.put('C', 'Y'); mapCharDecod.put('Z', 'A'); mapCharDecod.put('X', 'B'); mapCharDecod.put('Y', 'C'); final String toCod = "CAB"; StringBuilder sb = new StringBuilder("{"); for (final char c : toCod.toCharArray()) { sb.append(mapCharCod.get(c)); sb.append(','); } sb.setCharAt(sb.length() - 1, '}'); System.out.println(sb.toString()); f

Categories : Java

Replace non UTF compliant characters characters in a meaningful way rather than simply removing them
The javadoc for StringBufferInputStream says Deprecated. This class does not properly convert characters into bytes. As of JDK 1.1, the preferred way to create a stream from a string is via the StringReader class. Don't use it. The file is read as bytes, no matter where it comes from. Never convert your data to a String if you need it as bytes in the first place. If you're reading from a file, use a FileInputStream. (Never use FileReader, since it doesn't allow you to specify the encoding.)

Categories : Java

Replace Text Between 2 Characters in Vim
While the cursor is anywhere inside the square brackets, you can use: ca[_ARRAY_ To help you remember: c change a around [ square brackets _ARRAY_ with _ARRAY_

Categories : Shell

how to replace characters in hive?
There is no OOTB feature at this moment which allows this. One way to achieve that could be to write a custom InputFormat and/or SerDe that will do this for you. You might this JIRA useful : https://issues.apache.org/jira/browse/HIVE-3751. (not related directly to your problem though).

Categories : Hadoop

Find characters and replace
Your code works. You can use the below code to loop thru bad characters. Sub Finding() Dim badChar As String, str_bad As String badChar = ".@" For i = 1 To Len(badChar) str_bad = Mid(badChar, i, 1) Columns(4).Replace What:=str_bad, Replacement:="BAD Character", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False Next End Sub Getting wildcards to work in find and replace function in VBA macro

Categories : Excel

Sed replace all characters until first space
This will replace /tmp/tmp/... with aaa: $ sed 's/(.*=)[^ ]* (.*)/1 aaa 2/g' <<< "-Djava.util.logging.config.file=/tmp/tmp/tmp/config bla.bla" -Djava.util.logging.config.file= aaa bla.bla It "saves" anything up to = in 1. Then fetches everything up to an space. Finally "saves" the rest of the string in 2. The replacement is done by echoing 1 + "new string" + 2.

Categories : Regex

Replace characters with accents - ios
you could use the NSString method -(NSString*)stringByReplacingOccurrencesOfString:withString: for each accentuated symbol. For example, for the ó in Depósitos, you could use this: NSString *depositosCorrecto = [depositosIncorrecto stringByReplacingOccurrencesOfString:@"ó" withString:@"ó"]; So, how can you get those extrange symbols in xCode? Just do as i did, copy an paste them from where you're getting it written. Hope it helps! Lucas EDIT I found this table that may be helpful.

Categories : IOS

JQuery Characters replace
You need to use RegEx and specify global flag: $("textarea").val( $("textarea").val().replace(/s{2,}/g,",") ); this is for arbitrary number of spaces, more or equal then 2

Categories : Jquery

replace
with characters/string using css?
Self-closing tags (eg. <br>, <img>, <input>, etc) can't have generated content. These are replaced elements. For more information on replaced elements, see this article:http://www.red-team-design.com/css-generated-content-replaced-elements

Categories : CSS

How to replace the first k characters of a string?
Based on Change string char at index X. Given the string $foo, to change the first k characters by a string $pattern, this can make it: for ((i=0; i < $k; i++)) do foo="${foo:0:$i}$pattern${foo:$((i+1))}" done Test $ a="hellomynameisyou" $ k=5 $ pattern="x" $ for ((i=0; i < $k; i++)); do a="${a:0:$i}$pattern${a:$((i+1))}"; echo $a; done xellomynameisyou xxllomynameisyou xxxlomynameisyou xxxxomynameisyou xxxxxmynameisyou For your specific example $ pattern="Z" $ k=3 $ a="foobar" $ for ((i=0; i < $k; i++)); do a="${a:0:$i}$pattern${a:$((i+1))}"; echo $a; done Zxxbar ZZxbar ZZZbar $ echo $a ZZZbar

Categories : Linux

Replace by area on Matlab
Convert your mask to a logical matrix: mask = mask > 0 And then go ahead and multiply a with the mask and b with the inverted mask: c = mask .* a + ~mask .* b

Categories : Matlab

Function to replace different characters in a string
You can use a regular expression to match the different characters, and a callback function to determine what to replace it with. As it does all replacements in one run, there is no problem with one replacement containing another thing to replace: s = s.replace(/[ab]/g, function(m){ switch (m) { case 'a': return 'ab'; case 'b': return 'c'; } return m; }); Demo: http://jsfiddle.net/Guffa/pXSM5/ Edit: To use regular expressions for matching each string, loop through them and find every match, then loop through the found matches and replace them. It's easiest to do the replacements starting with the last one in the string, that way you don't have to adjust the index of other matches when a replacement has a different length from the matched string: var s = "a b"; var re =

Categories : Javascript

Replace only few characters from list python
Use this : x.replace(",","-",3) str.replace has a third optional argument count. help on str.replace: S.replace(old, new[, count]) -> string Return a copy of string S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.

Categories : Python

Replace Non-Alphanumeric Characters in Oracle
I don't think you can get there with plain SQL without nested replace calls. You can get your sample value with the utl_url.escape() function, but because you have to pass it a second parameter and that is a boolean, you have to do it in an PL/SQL block: begin dbms_output.put_line(replace(utl_url.escape('Project 1: Nuts & Bolts', true), '%20', '+')); end; / Project+1%3A+Nuts+%26+Bolts The url_utl.escape function converts the spaces to %20: Project%201%3A%20Nuts%20%26%20Bolts ... and the single replace call converts those to +. As Ed Gibbs said, you can make that a function so you can at least call it from plain SQL: create or replace function my_escape(str in varchar2) return varchar2 is begin return replace(utl_url.escape(str, true), '%20', '+'); end; / select my_e

Categories : String

Regex to replace multiple characters
The + symbol means that it should accept one or more of each of the characters in the group. If you want only one, then you need to remove the +. negWords.replace(/[,.!?;s]/g,' '); If you want to catch one punctuation character or space followed any amount of whitespace, try this: negWords.replace(/[,.!?;s]s*/g,' ');

Categories : Javascript

Replace specific word between characters using sed?
Really dorky approach: $ sed 's/and/or/g' INPUT | sed 's/) or (/) and (/' | sed 's/(.*)or/1and/' (grade='C' or grade='D' or grade='E') and (int_rate>=10 or int_rate<=20) and pub_rec>=0 and term=' 36 months'

Categories : Regex

how to replace characters in a string with integers?
Do you only have binary operands? Just do replaceAll("a", "0"); replaceAll("b", "1"); Edit: Since you want to evaluate your equation, I suggest you used the solution above, then use a java math parser. Several can be found after a quick googling. My favourite is Javaluator.

Categories : Java

regex replace characters within tags
How about something like this? In this example I'm creating a variable and populating the variable with html, just to get things started var doc = document.createElement( 'div' ); doc.innerHTML = ---your input html here Here I'm pulling the code tag var string = doc.getElementsByTagName( 'code' ).innerHTML; Once you have the string then simply replace the desired brackets with var string = string .replace(/[<]/, "&#60;) var string = string .replace(/[>]/, "&#62;) then just reinsert the replaced value back into your source html

Categories : Javascript

Replace all non-printable UTF-8 characters with spaces
According to the PHP regex character classes [:print:] includes "printing characters, including space". That means "Visible characters and spaces (i.e. anything except control characters, etc.)" (see http://www.regular-expressions.info/posixbrackets.html) ASCII characters: [x20-x7E] Unicode: P{C}

Categories : PHP

Replace occurrences of two characters with each other in a string
string = @"a*b/c"; [string stringByReplacingOccurrencesOfString:@"*" withString:@"&"]; [string stringByReplacingOccurrencesOfString:@"/" withString:@"*"]; [string stringByReplacingOccurrencesOfString:@"&" withString:@"/"];

Categories : Objective C

SQL - Replace non numeric characters in string
Try this DECLARE @string VARCHAR(100) DECLARE @outstring VARCHAR(100) DECLARE @wcount INT DECLARE @temp INT DECLARE @index INT DECLARE @len INT DECLARE @char CHAR SET @string = '1a2a3a4a' SET @wcount= 0 SET @index = 1 SET @len= LEN(@string) SET @outstring = '' WHILE @index<= @len BEGIN SET @char = SUBSTRING(@string, @index, 1) IF @char LIKE '%[a-z]%' BEGIN SELECT @temp = REPLACEMENT FROM #Conversion_Tab WHERE EXPR = @char SET @outstring = @outstring + CONVERT(VARCHAR(10),@temp) END ELSE BEGIN SET @outstring = @outstring + @char END SET @index= @index+ 1 END SELECT @outstring SQL FIDDLE DEMO

Categories : SQL

using DocumentFilter.replace with unicode characters
How about creating a global variable to keep track of whether your callback has been called for this B event? It can be a simple Boolean flag that flips each time the B event is generated. You only output B when the flag is true.

Categories : Java

How can I replace non zero elements randomly with zero in matlab?
The function find is your friend: indices = find(A); This will return an array of the indices of 1 elements in your matrix A and you can use your method of replacing a percent of elements with zero on a subset of this array. Then, A(subsetIndices) = 0; will replace the remaining indices of A with zero.

Categories : Matlab

Replace several characters in substring in batch file
set str=%1 set str=%str:""="% set str=%str: =^|% echo %str:|=^|% pause Just worked for me with your test case. You get the "3"" is not recognized error because of the pipe | character, as it means that CMD is trying to pass the text before the | to the 'program' after it, which is why you'll notice I've used ^| to 'escape' the pipe and stop it from having it's special meaning

Categories : Windows

Regex - replace character with alternating characters
If you are only replacing underscores, you can probably do this without regex. By using the replaceFirst() method in whichever language your using. With regex you would only be detecting underscores and replacing them, same as this. Something like; myURL = myURL.replaceFirst("_",".cfm?"); while(myURL.contains("_")) { myURL = myURL.replaceFirst("_","="); myURL = myURL.replaceFirst("_","&"); } If you need a more complicated one to prevent detection of underscores in other parts of the URL if you outline what the possible combinations for that are I can probably help you find a suitable pattern to separate the domain from the parameters prior to replacement. According to the download page, you are doing this in .net? http://www.iis.net/downloads/microsoft/url-rewrite Ok I'v

Categories : Regex

How to replace exact string containing characters @ and # in java
I think what you want is: mytext.replaceAll("(^|\W)("+text+")($|\W)", "$1"+replacement+"$3")) The problem with  in your solution is that it only matches [a-zA-Z0-9_] and # as well as @ separate your words instead of being included.

Categories : Java

javascript replace() is not replacing all the characters match
Use a regex with the g flag. var $id = id.replace(///g, '_');

Categories : Javascript

replace semicolon (;) but not html characters (  etc.)
If you must use the regular expression, you can step like this: remove all character, except w : ; & replace all &copy; to @@@copy### you can replace the : ; with <td> now replace all @@@copy### to &copy; remove all &nbsp;

Categories : PHP

Python Program - Replace characters into 4 symbols
change line = line.replace('a', '$').replace('b', '£').replace('c', '=').replace('d', '¬') into for c in line: modLine = modLine + chr(ord(c) + 98) + chr(ord(c) + 99) + chr(ord(c) + 100) + chr(ord(c) + 101) line = modLine ord(c) returns the char number of c, and chr(ord(c) + n) adds n to the char number and then reconverts it to a character.

Categories : Python

how to replace characters or remove them in golfscript efficiently
# remove any 'l' 'hello world' 'l'- puts # replace all 'l' with 'X' 'hello world' 'l'/ 'X'* puts Please also have a look into the page for GolfScript built-ins.

Categories : Misc

Replace all selected characters inside the file
You write double the text because you are calling write() twice. Try something like newLine = line newLine.replace('a', '~') newLine.replace('b', '~') f2.write(newLine)

Categories : Python

Quickest way to replace series of characters from start and end in T-SQL
Try this way: DECLARE @Number VARCHAR(64) SET @Number = '123456789' select '**'+substring(@Number,3,len(@Number)-4)+'**' SQL Fiddle Demo

Categories : SQL

Use Powershell to replace characters within a specific string
Try this regex: "(?<!?xml.*)(?<=`".*?)`"(?=.*?`")" In your code it would be: (Get-Content C: estcommunication.xml) | Foreach-Object {$_ -replace "&", "+" ` -replace "£", "GBP" ` -replace "'", "" ` -replace "–", " " ` -replace "(?<!?xml.*)(?<=`".*?)`"(?=.*?`")", ""} | Set-Content C: estcommunication.xml This will take any " that has a " in-front of and behind it (except a line that has ?xml in it) and replace it with nothing. Edit to include breakdown of regex; (?<!?xml.*)(?<=`".*?)`"(?=.*?`") 1. (?<!?xml.*)----> Excludes any line that has "?xml" before the first quote 2. (?<=`".*?)------> Lookbehind searching for a quotation mark. The ` is to escape the quotation mark, which is needed for powershell 3. `"--------------

Categories : Xml

Objective-C: Randomly replace characters in string
If the number of characters to remove/replace is small compared to the length of the string, then your solution is good, because the probability of a "collision" in the while-loop is small. You can improve the method by using a single mutable string instead of allocating a new string in each step: NSString *string = @"Remove Some Characters"; int totalRemove = 5; NSMutableString *result = [string mutableCopy]; for (int j=0; j < totalRemove; j++) { int replaceLocation; do { replaceLocation = arc4random_uniform((int)[result length]); } while ([result characterAtIndex:replaceLocation] == '_' || [result characterAtIndex:replaceLocation] == ' '); [result replaceCharactersInRange:NSMakeRange(replaceLocation, 1) withString:@"_"]; } If the number of characters to r

Categories : Objective C

Allowing new line characters in javascript str.replace
A way to avoid problems with newlines is to not use the dot, example: var n=str.replace(/<i>([^<]+)</i>/,"$1"); I have replaced the dot by [^<] (all that is not a <, that include newlines) the m modifier is not needed here, and you don't need to capture white characters too. Note that my solution suppose that you don't have any < between <i> and </i> In the other case, when you have nested tags for example, you can use this trick to avoid lazy quantifier: var n=str.replace(/<i>((?:[^<]+|<+(?!/i>)+)</i>/,"$1");

Categories : Javascript

Replace specific characters in std::string with spaces
You could use std::replace_if: bool fun(const char& c) { return std::ispunct(static_cast<int>(c)); } int main() { std::string line = "ts='TOK_STORE_ID'; one,one, two;four$three two"; std::replace_if(line.begin(), line.end(), fun, ' '); }

Categories : C++

Regular expression - replace special characters, except dot
Use this for the regex instead: /[^w.]|_/g It reads any character that is not either alpha-numerical (which includes underbars) or dot, or that is an under bar. update But this is perhaps little more readable: /[^0-9a-zA-Z.]/g

Categories : Javascript

How to handle when some special UTF-8 characters are inside a XML file in matlab
The sample you posted works just fine. As the error message says, I think your actual files are incorrectly encoded. Remember that not all possible byte sequences are valid UTF-8 sequences: http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences A quick way to check is to open the file in Firefox. If the XML file has encoding problems, you'll see an error message like: XML Parsing Error: not well-formed EDIT: So I took a look at the file: Your problem is that XML parsers treat files without the <?xml ... ?> declaration line as UTF-8, but your file looks to be encoded as ISO-8859-1 (Latin 1) or Windows-1252 (CP-1252) instead. For instance, the SAX parser choked on the following token: Baños. This character "n letter with tilde", which is U+00F1, has different representa

Categories : Xml

JavaScript Regex - Replace all word characters except word characters between character X and character Y
'&nbsp;John &amp; Sandy are awesome & rock; They are also weird.'.replace( /(&[^s;]*;)|w/g, function(a, b) { return b || '*'; }); The result: &nbsp;**** &amp; ***** *** ******* & ****; **** *** **** *****. Tried and works for me in Firefox and Chrome.

Categories : Javascript

find and replace characters in a particular column in a table using python
You can use regular expressions: import re PARCEL_ID = re.sub(r'[-/ ]', '', PARCEL_ID) Add any other characters you don't want between the brackets.

Categories : Python



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