» Home » replace » Page 1
python3: removing several chars from a string with a long chain of .replace().replace().replace()
Category : Programming Languages

I found this example on stack overflow. I understand it, but seems like a bit much for such a simple method concept... removing several chars from a string.

import string
exclude = set(string.punctuation)
s = '.join(ch for ch in s if ch not in exclude)

is there a builtin string method in python 3.1 to do something to the tune of:

s = "a,b,c,d,e,f,g,h,i"

View Replies

Regex.Replace, String.Replace or StringBuilder.Replace which is the fastest?
Category : Programming Languages

I need to replace all System.Environment.Newline(s) in the string returned by my function with System.Environment.Newline + (as I am trying to apply indenting) and I need to do this several times.

My question is which one is the most efficient way to do this?

I know that StringBuilder is faster than String.Replace but

View Replies

Regex: Replace WITH REPEATED strings , not “replace repeat”
Category : Programming Languages

Could we replace a matched pattern with a REPEATED pattern USING regular expression?

For example :
the target string is "abc2:4def" , what I want is abc2222def, that means the "4" is a repeater in the target string and I want to compose my string back to "uncompressed" format.

I could think of the back reference in sed,

sed '

View Replies

Javascript replace with regular expression - Replace only part of string found
Category : Programming Languages

I have a string that looks like the following:

"01/11/2012 (Last, First) - Notes,02/11/2012 (Last, First) - More Notes,03/11/2012 (Last, First) - Even More Notes,09/12/2012 (Last, First) - You get the idea"

I would like each note to fall on a new line by replacing any comma followed by a number with '

I have tried .replace(/,/g, '

View Replies

Replacing multiple string Replace() with a single Regex.Replace()
Category : Programming Languages

if I'm doing something like that:


How can I replace that with

Regex.Replace(someString," here I don't know what the pattern should be")

I've tried this:

Regex.Replace(someString, @"(?:abc|def|c:Windows)")

but it didn

View Replies

How to replace all characters in a string using JavaScript for this specific case: replace . by _
Category : Javascript

The following statement in JavaScript works as expected:

var s1 = s2.replace(/ /gi, '_'); //replace all spaces by the character _

However, to replace all occurrences of the character . by the character _, I have:

var s1 = s2.replace(/./gi, '_');

But the result is a string entirely filled with the character _


View Replies

How to replace broken German Umlauts with MySQL REPLACE function?
Category : Development Tools & Services

(I accidentially asked this question first on DBA but found out in the FAQ to ask SQL questions here on SO instead)

I'm trying to "repair" a MySQL database (UTF-8 collation) that was imported from an encoding-broken SQL text file.

I.e. the German umlauts are broken inside the database. What should read e.g. "ü" is displayed as "ü".

Since I'm aware of the

View Replies

RegEx.Replace to Replace Whole Words and Skip when Part of the Word
Category : Programming Languages

I am using regex to replace certain keywords from a string (or Stringbuilder) with the ones that I choose. However, I fail to build a valid regex pattern to replace only whole words.

For example, if I have InputString = "fox foxy" and want to replace "fox" with "dog" it the output would be "dog dogy".

What is the valid RegEx pattern to take only "fox" and leave "foxy"?

View Replies

Regex replace - how to replace same pattern in multiple places with different strings?
Category : Programming Languages

I have a peculiar problem..!

I have a string with some constant value at multiple paces. For example consider the following sting.

string tmpStr = "Hello _tmp_ how is _tmp_ this possible _tmp_ in C#...?"

Now i want to replace each of the tmp in the string with values that are stored in an array, first tmp holds array[0], second tmp holds array[1]

View Replies

Android - fragment .replace() doesn't replace content - puts it on top
Category : Programming Languages


FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment1 fragment = new Fragment1();
Fragment2 fragment2 = new Fragment2();
transaction.replace(R.id.Fragment1, fragment);

View Replies

2012 / 2017 Copyrights BigHow , All Rights Reserved .