w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Need help writing a regex string to remove string with variable number
Include a pattern delimiter (in this case ~): $string = preg_replace('~::tt::[0-9]+::/tt::~', '', $string );

Categories : PHP

serialize Dictionary and remove key/value from json string
Its because you are using dictionary for storing the value. You have to write a custom implementation and overide serialization/deserialization methods Look here for more details

Categories : C#

How do I remove an entry from List> based on just the key?
Use List.RemoveAll. You can pass in a predicate which checks the key value. Example: myList.RemoveAll(kvp => kvp.Key == "@index");

Categories : C#

Remove everything from a string upto a certain character and optionally a string if it follows too
Try this: String removeEmsp =" &ldquo;[<centd>[</centd>]&sect;&ensp;431:10A&ndash;126&emsp;(new section)[<centd>]Chemotherapy services.</centd>] <centa>Cancer treatment.</centa>test snl."; System.out.println(removeEmsp.replaceFirst("^.*?\&emsp;(\(new\ssection\))?", "")); System.out.println(removeEmsp.replaceAll("^.*?\&emsp;(\(new\ssection\))?", "")); Output: [<centd>]Chemotherapy services.</centd>] <centa>Cancer treatment.</centa>test snl. [<centd>]Chemotherapy services.</centd>] <centa>Cancer treatment.</centa>test snl. It will remove everything up to "&emsp;" and optionally, the following "(new section)" text if any.

Categories : Java

Remove/Count spaces in a string (using the same string)
1) Last spaces don't be cut too. Add check and action after loop. 2) I recommend to divide notions of local space counter and global space counter. unsigned int contEsp = 0; unsigned int i = 0; unsigned int localEsp = 0; while(str[i] != ''){ if(str[i] == ' '){ contEsp += 1; localEsp += 1; }else if(contEsp) { strcpy(&str[i - localEsp], &str[i]); localEsp = 0; continue; } i++; } if ( localEsp > 0 ) strcpy(&str[i - contEsp], &str[i]);

Categories : C

how to remove specific String from String in java
I suspect that 2005:0.056 Top Terms: Weight : is actually a single line ... somehow. That regex should (only) match lines where you have a "word" consisting of a single digit. I'm guess that you actually know this (and you "forgot to mention it"). If you want to match these: 2005:0.056 15th:0.023 1st:0.023 2nd:0.023 3rd:0.023 but not these: 2005:0.056 Top Terms: Weight : 1.0: then you need a stricter regex, and match() rather than find; e.g. pattern = Pattern.compile( "\s*[0-9]+(st|nd|rd|th|(\.[0-9]+))?:[0-9]+\.[0-9]+\s*"); for (String t1: Result) { matcher = pattern.matcher(t1); if (matcher.match()) { System.out.println(t1); } } But at this point I'm guessing what your actual criterion for a "valid" line is.

Categories : Java

I want to remove all charactors from string /integer from string in php
Try this : $string='Tel. 040- 36 49 03 SEC'; echo preg_replace("/[A-Za-z]+/","",$string); Do you want to remove . and - also ? echo preg_replace("/[A-Za-z-. ]+/","",$string); // this will just give you number, removes all characters

Categories : PHP

I am trying to remove characters in a string from a defined string. the error comes here: if(s.charAt(x) == punct.charAt(y))
I'm a smidge drunk, but it looks like you check the length of your string at the beginning of the loop, then you start removing characters from it, and your loop overruns the end of the string. You need a while loop I think, so you can check that your index is within bounds before every iteration. int x = 0; while(x < s.length()) { for(int y = 0; y < punct.length(); y++) { if(s.charAt(x) == punct.charAt(y)) { s = s.replace("" + s.charAt(x), ""); } } x++; } It's ugly cause I'm on a tablet, but I think it works.

Categories : Java

cut a string from right side to maximal 25 chars even when string is less than 25 chars, remove newlines of all kinds
It seems, that there's no ready function in a framework, but you can do something like this: public static String Preview(String value) { String[] newLines = new String[] { "<br>", "<br />", " ", " ", Environment.NewLine }; foreach (String newLine in newLines) value = value.Replace(newLine, ""); // <- May be space will be better here if (text.Length > 25) return value.Substring(0, 25) + "…"; // If you want string END, not string START, comment out the line above and uncomment this // return value.Substring(value.Length - 25) + "…"; else return value; } ... // Test sample String text = "abcd<br>efgh 1234567890zxy 1234567890abc"; String result = Preview(text); // <- abcdefgh1234567890zxy1234

Categories : C#

Remove everything between ? and # in string
Using regular expressions: var s = 'http://localhost:8080/Test/index.html?node=station:|slot:/gooberVille/Neverland/Hola#/overview/standard'; s = s.replace(/?.*?#/, ''); ? is a special character in regular expressions, so to match a literal ? you escape it with a backslash. . matches any character, .* matches any number of any character (as many as possible), and .*? matches any number of any character (as few as possible). So /?.*?#/ will match starting from the first ?, then as few characters as possible until a # is found. By replacing a match of this regex with an empty string you get the result you want. If you want to keep the # in the string, just change it to s.replace(/?.*?#/, '#').

Categories : Javascript

Remove a string from php
You could simply do it in two steps: <?php $lang = str_replace('en', '', substr(JFactory::getLanguage()->getTag(), 0, 2)); $url = 'http://www.mysite.com/'.$lang.'/pages.html'; $url = str_replace('//', '/', $url); ?> <link rel="canonical" href="<?php echo $url; ?>" />

Categories : PHP

Remove � from string
You can remove � as follows. may be issue with character encoding. It has Unicode value 0xFFFD String returnStr="[��BMW 320d Xdrive, 222201176��]"; System.out.println(returnStr.replaceAll("\[|\]|\�",""));

Categories : Java

How to remove a used string
You have to rewrite the entire file: Dim newLines = File.ReadAllLines(path). .Where(Function(l) Not l.Trim.Equals(stN, StringComparison.OrdinalIgnoreCase) ) File.WriteAllLines(path, newLines) If you don't want to use Trim and the case insensitive comparison: .Where(Function(l) l <> stN) Edit: Are you using .NET 3.5? Then File.WriteAllLines does not accept an IEnumerable(Of String) but only String(). You need to create one from the query: File.WriteAllLInes(path, newLines.ToArray())

Categories : Vb.Net

How do you remove from a string?
Try This. NSString *string = @"Whats Going on "; NSString *result = [string stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; or the simple way as we used to replace a particuler string into string. like string = [string stringByReplacingOccurrencesOfString:@" " withString:@" "];

Categories : Objective C

Remove or from a given string
It looks like you also want to remove spaces. You can do something like this, >>> import re >>> s = "abc efg" >>> s = re.sub('s+', '', s) >>> s 'abcefg' Another way would be to do, >>> s = "abc efg" >>> s = s.translate(None, ' ') >>> s 'abcefg'

Categories : Python

How to remove whitespace between a tag until the string?
Your regexp works perfectly: <?php $str = "<td> Some text</td><td> July 3, 2013</td>"; $str = preg_replace('/<td>s+/', '<td>', $str); print $str; prints: <td>Some text</td><td>July 3, 2013</td>

Categories : PHP

How to remove every second occurrence within a string?
In your specific case, you may want to just replace two newlines with one newline: $string = str_replace(" ", " ", $string); More complicated regex solutions could collapse any number of concurrent newlines: preg_replace("/ +/", " ", "foo bar blee nope");

Categories : PHP

Remove a prefix from a string
regex solution (don't use, use the solution by @Elazar) import re def remove_prefix(text, prefix): return re.sub(r'^{0}'.format(re.escape(prefix)), '', text) >>> print remove_prefix('template.extensions', 'template.') extensions

Categories : Python

How to remove first word from a string?
You can do it without a stream: skip the initial spaces, locate the first space after that, walk to the next non-space, and use substr to get the rest of the string: int i = 0; while (isblank(str[i])) i++; while (!isblank(str[i])) i++; while (isblank(str[i])) i++; str = str.substr(i); Here is a demo on ideone.

Categories : C++

How to remove a char in string using vb.net?
Function RemoveTrailingSlash(ByVal s as String) As String 'Note that space is included in this array Dim slash() As Char = "/ ".ToCharArray() s = s.TrimEnd() While s.EndsWith("/") s = s.TrimEnd(slash) End While Return s End Function Typed directly into the reply window (not tested!), but I think it will work.

Categories : Asp Net

How to remove certain part of string
EDIT: Now with more than one digit (or any other characters inside the brackets). Use: current_title = current_title.substring(current_title.indexOf(')')); This should return the rest of the string after the closing bracket. Check out the function documentation.

Categories : Javascript

how to remove %20 from query string URL in JSP
Use this: ('printlist.jsp?CTextSearch=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtSearch"),"UTF-8")%>&CTextNumbr=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtNum"),"UTF-8") %>&CYear=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbYear"),"UTF-8") %>&CSectionNo=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbSection"),"UTF-8") %>&CDatefrom=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateFrom"),"UTF-8") %>&CDateto=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateTo"),"UTF-8") %>' instead of ('printlist.jsp?CTextSearch=<%=URLEncoder.encode(request.getParameter("ctl00$S

Categories : Java

remove every other string entry
If the minimum is always first and the maximum always second. All you need to do is change tTemp += toldata.substring(3,toldata.length()-3).replace(" ", " ") + " "; to tTemp += toldata.substring(3,toldata.length()-3).split(" ")[c] + " "; where c is 0 for the first (minimum) and 1 for the second (maximum). or a simpler tTemp += toldata.split(" ")[c] + " "; where c is 2 or 3 in the respective cases. This of course assumes the string is always in the exact form: " [ number number ] " (always with exactly the same amount of spaces in the exact same positions). A simple regular expression of "\s+" instead of " " will allow one or more spaces instead, i.e.: tTemp += toldata.split("\s+")[c] + " "; s means white-space and + means one or more. The additional is to escape the for th

Categories : Java

Remove Last Comma from a string
The problem is that you remove the last comma in the string, not the comma if it's the last thing in the string. So you should put an if to check if the last char is ',' and change it if it is. EDIT: Is it rly that confusing? 'This, is a random string' Your code finds the last comma from the string and stores only 'This, ' because the last coma is after 'This' not at the end of the string.

Categories : Javascript

remove '$' characters from a string
yup, that's a special character for pattern matching. you need to escape it with the % symbol. local s = 'asdf$erer$iiuq' print(s:gsub('%$', '')) > asdfereriiuq 2

Categories : Regex

Remove sub-quoting in string
If you have XML then use it to loop at every <quote>. When you have it in loop you can use strip_tags() to remove subquotes. You can use SimpleXML for that. There's no need to use "crazy regexp" This link shows how to remove item with specific attribiute you can use it to fit your needs.

Categories : PHP

Remove string starting with something
Are you always expecting the end part to have the 'yy' variable name? You could try this: $str = 'http://www.example.com/index.php?&xx=okok&yy=no&bb=525252'; $ex = explode('&yy=', $str, 2); $firstPart = $ex[0];

Categories : PHP

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#

Remove part from string
With a regular expression : var str2 = str1.replace(/-.{8}.ext$/, '.ext'); If the extension may change (for example .odt instead of .txt , use var str2 = str1.replace(/-.{8}(.[dw]+)$/, '$1');

Categories : Javascript

Regex How to remove last ; from a string?
The following regex should work for you: ;(?=[^;]*$) So your replacement code would become: (;(?=[^;]*$), ""); Here is an example of the regex working on RegExr.

Categories : Dotnet

PHP remove timestamp from string
you could use a simple explode or as noted in the comments substr but if you don't know how the string will be formatted a more complex date('Y-m-d', strtotime($mytime)) based on your updated post... $newdate = substr($olddate,0,10);

Categories : PHP

How can I remove #N/A in a formula string
You can wrap your equation in IfError, e.g. =IFERROR(YourEquation,"") Whatever you put in place of the "" is what will be placed in the cell if the formula evaluates to an error. In this case it would appear as a blank cell.

Categories : Excel

remove int, char from string
If word is your method.. then its an invalid declaration... For Any method you create you need to have a return type.. i.e., If method returns value(suppose int) then it need to be public int word(String S){} If the method doesn't return any value then it need to be public void word(String S){} If you want to construct a constructor.. the constructor name and class name need to be same.. public World(String S){}

Categories : Java

Remove tags in string
Use String.Replace to replace commas with empty strings. Dim movieData as String = "{""Title"":""True Grit"",""Year"":""1969""}" movieData = movieData.Replace(",", "")

Categories : Vb.Net

how to remove the character '%' from string in sql
How about the mysql replace function? Check out this stackoverflow question as well. For SQL server, this has been answered here

Categories : Sql Server

how to remove span tag from the string?
Try var mystring = 'In open <span class="">court</span> at 11:01 a.m.) THE <span class="">COURT</span>: Our interpreter. (NOTE: Spanish interpreter Rosa Lopez-Gaston sworn.) SPEAKER 2: Judy Faviell for the State. SPEAKER 1: Carey Bhalla for Mr. Garcia, who is present in custody, Your Honor. SPEAKER 2: Judge, we do have a change of plea, which I will tender to the <span class="">Court</span>.THE <span class="">COURT</span>:'; var after = $('<div />').html(mystring).find('span').contents().unwrap().end().end().html(); Demo: Fiddle

Categories : Javascript

Remove comma from end of this string?
Remove the trailing comma in your expression here: $arr = array("data"=>"[Date.UTC(".$date."), ".$pos." ],"); ^ Remove this Then outside the loop use $teststring = implode(",", $arr); That should create your required string without the trailing comma

Categories : PHP

Remove all elements if contain a string
The problem is, when you remove an item, you change the collection's indexing (ie, the item at i=1 moves to 0). To correct this, iterate backwards: for (i = elemItem.length-1; i >= 0 ; i--) {

Categories : Javascript

How can I capture a value from a string and then remove it?
Using regex: import re s = '42Xmessage' pattern = re.compile("([0-9]+)X") print pattern.findall(s)[0] For this part of your question: "How can I get the number in a variable and then get the message part (without the number and X) in another variable?" import re s = '42Xmessage' pattern = re.compile("([0-9]+)X([a-z]+)", re.IGNORECASE) num, msg = pattern.findall(s)[0][:2] For the pattern, [0-9] is the number set from 0 to 9. ([0-9]+)X finds any number followed by an X. Similarly, X([a-z]+), any string after the X.

Categories : Python

Remove any comma before or after a string?
You can use anchors for this: $result = preg_replace('/^,|,$/', '', $subject); If you want to match one or more commas at the start/end of the string: $result = preg_replace('/^,+|,+$/', '', $subject); And if there could be whitespace around those leading/trailing commas: $result = preg_replace('/^[,s]+|[s,]+$/', '', $subject);

Categories : PHP



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