Search Results

Search found 37051 results on 1483 pages for 'string matching'.

Page 3/1483 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • C# String.Replace with a start/index (Added my (slow) implementation)

    - by Chris T
    I'd like an efficient method that would work something like this EDIT: Sorry I didn't put what I'd tried before. I updated the example now. // Method signature, Only replaces first instance or how many are specified in max public int MyReplace(ref string source,string org, string replace, int start, int max) { int ret = 0; int len = replace.Length; int olen = org.Length; for(int i = 0; i < max; i++) { // Find the next instance of the search string int x = source.IndexOf(org, ret + olen); if(x > ret) ret = x; else break; // Insert the replacement source = source.Insert(x, replace); // And remove the original source = source.Remove(x + len, olen); // removes original string } return ret; } string source = "The cat can fly but only if he is the cat in the hat"; int i = MyReplace(ref source,"cat", "giraffe", 8, 1); // Results in the string "The cat can fly but only if he is the giraffe in the hat" // i contains the index of the first letter of "giraffe" in the new string The only reason I'm asking is because my implementation I'd imagine getting slow with 1,000s of replaces.

    Read the article

  • Javascript string replace with calculations

    - by Chris
    Is there a way to resolve mathematical expressions in strings in javascript? For example, suppose I want to produce the string "Tom has 2 apples, Lucy has 3 apples. Together they have 5 apples" but I want to be able to substitute in the variables. I can do this with a string replacement: string = "Tom has X apples, Lucy has Y apples. Together they have Z apples"; string2 = string.replace(/X/, '2').replace(/Y/, '3').replace(/Z/, '5'); However, it would be better if, instead of having a variable Z, I could use X+Y. Now, I could also do a string replace for X+Y and replace it with the correct value, but that would become messy when trying to deal with all the possible in-string calculations I might want to do. I suppose I'm looking for a way to achieve this: string = "Something [X], something [Y]. Something [(X+Y^2)/5X]"; And for the [_] parts to be understood as expressions to be resolved before substituting back into the string. Thanks for your help.

    Read the article

  • Java String.indexOf and empty Strings

    - by tmeisenh
    I'm curious why the String.indexOf is returning a 0 (instead of -1) when asking for the index of an empty string within a string. The Javadocs only say this method returns the index in this String of the specified string, -1 if the string isn't found. System.out.println("FOO".indexOf("")); // outputs 0 wtf!!! System.out.println("FOO".indexOf("bar")); // outputs -1 as expected System.out.println("FOO".indexOf("F")); // outputs 0 as expected System.out.println("".indexOf("")); // outputs 0 as expected, I think

    Read the article

  • Using string.Format for simple things?

    - by Gerrie Schenck
    In my early .Net programming days, I used string.Format() only for complex string concatenations, for example to compile strings as Problem with customer order 234 of date 2/2/2002 and payment id 55543. But now I use string.Format for almost every string concatenation I have to do, also simple ones such as prefixing a string with something. Console.WriteLine(string.Format("\t\t{0}", myString)); Is there any possible overhead on this? Maybe I should use the regular + operator to do these simple operations? What's your opinion on this?

    Read the article

  • Split String in C# without delimiter (sort of)

    - by Zach
    Hi, I want to split a string in C#.NET that looks like this: string Letters = "hello"; and put each letter (h, e, l, l, o) into an array or ArrayList. I have no idea what to use as the delimiter in String.Split(delimiter). I can do it if the original string has commas (or anything else): string Letters = "H,e,l,l,o"; string[] AllLettersArray = Letters.Split(",".ToCharArray()); But I have no idea what to use in a case with (supposedly) no delimiter. Is there a special character like Environment.Newline? Thanks.

    Read the article

  • Parse string to create a list of element

    - by Nick
    I have a string like this: "\r color=\"red\" name=\"Jon\" \t\n depth=\"8.26\" " And I want to parse this string and create a std::list of this object: class data { std::string name; std::string value; }; Where for example: name = color value = red What is the fastest way? I can use boost. EDIT: This is what i've tried: vector<string> tokens; split(tokens, str, is_any_of(" \t\f\v\n\r")); if(tokens.size() > 1) { list<data> attr; for_each(tokens.begin(), tokens.end(), [&attr](const string& token) { if(token.empty() || !contains(token, "=")) return; vector<string> tokens; split(tokens, token, is_any_of("=")); erase_all(tokens[1], "\""); attr.push_back(data(tokens[0], tokens[1])); } ); } But it does not work if there are spaces inside " ": like color="red 1".

    Read the article

  • Numerical Pattern Matching

    - by Timothy Strimple
    A project I'm researching requires some numerical pattern matching. My searches haven't turned up many relevant hits since most results tend to be around text pattern matching. The idea is we'll have certain wave patterns we'll need to be watching for and trying to match incoming data vs the wave database we will be building. Here is and example of one of the wave patterns we'll need to be matching against. There is clearly a pattern there, but the peaks will not have the exact same values, but the overall shape of the wave iterations will be very similar. Does anyone have any advice on how to go about storing and later matching these patterns, and / or other search terms I can use to find more information on the subject of pattern matching? Thanks, Tim.

    Read the article

  • java - check if string ends with certain pattern

    - by The Learner
    I have string like: This.is.a.great.place.too.work. (or) This/is/a/great/place/too/work/ than my java program should give me that the sentence is valid and it has "work". if i Have : This.is.a.great.place.too.work.hahahha (or) This/is/a/great/place/too/work/hahahah Should not give me that there is a work in the sentance. so I am looking at java strings to find a word at the end of the sentance having . (or),(or)/ before it. How can I achieve that

    Read the article

  • Why String.replaceAll() don't work on this String ?

    - by Aloong
    //This source is a line read from a file String src = "23570006,music,**,wu(),1,exam,\"Monday9,10(H2-301)\",1-10,score,"; //This sohuld be from a matcher.group() when Pattern.compile("\".*?\"") String group = "\"Monday9,10(H2-301)\""; src = src.replaceAll("\"", ""); group = group.replaceAll("\"", ""); String replacement = group.replaceAll(",", "#@"); System.out.println(src.contains(group)); src = src.replaceAll(group, replacement); System.out.println(group); System.out.println(replacement); System.out.println(src); I'm trying to replace the "," between \"s so I can ues String.split() latter. But the above just not working , the result is: true Monday9,10(H2-301) Monday9#@10(H2-301) 23570006,music,**,wu(),1,exam,Monday9,10(H2-301),1-10,score, but when I change the src string to String src = "123\"9,10\"123"; String group = "\"9,10\""; It works well true 9,10 9#@10 1239#@10123 What's the matter with the string???

    Read the article

  • Truncate portions of a string to limit the whole string's length in Ruby

    - by Horace Loeb
    Suppose you want to generate dynamic page titles that look like this: "It was all a dream, I used to read word up magazine" from "Juicy" by The Notorious B.I.G I.e., "LYRICS" from "SONG_NAME" by ARTIST However, your title can only be 69 characters total and this template will sometimes generate titles that are longer. One strategy for solving this problem is to truncate the entire string to 69 characters. However, a better approach is to truncate the less important parts of the string first. I.e., your algorithm might look something like this: Truncate the lyrics until the entire string is <= 69 characters If you still need to truncate, truncate the artist name until the entire string is <= 69 characters If you still need to truncate, truncate the song name until the entire string is <= 69 characters If all else fails, truncate the entire string to 69 characters Ideally the algorithm would also limit the amount each part of the string could be truncated. E.g., step 1 would really be "Truncate the lyrics to a minimum of 10 characters until the entire string is <= 69 characters" Since this is such a common situation, I was wondering if someone has a library or code snippet that can take care of it.

    Read the article

  • getting string.substring(N) not to choke when N > string.length

    - by aape
    I'm writing some code that takes a report from the mainframe and converts it to a spreadsheet. They can't edit the code on the MF to give me a delimited file, so I'm stuck dealing with it as fixed width. It's working okay now, but I need to get it more stable before I release it for testing. My problem is that in any given line of data, say it could have three columns of numbers, each five chars wide at positions 10, 16, and 22. If on this one particular row, there's no data for the last two cols, it won't be padded with spaces; rather, the length of the string will be only 14. So, I can't just blindly have dim s as string = someStream.readline a = s.substring(10, 5) b = s.substring(16, 5) c = s.substring(22, 5) because it'll choke when it substrings past the length of the string. I know I could test the length of the string before processing each row, and I have automated the filling of some of the vsariables using a counter and a loop, and using the counter*theWidthOfTheGivenVariable to jump around, but this project was a dog to start with (come on! turning a report into a spreadsheet?), but there are many different types of rows (it's not just a grid), and the code's getting ugly fast. I'd like this to be clean, clear, and maintainable for the poor sucker that gets this after me. If it matters, here's my code so far (it's really crufty at the moment). You can see some of my/its idiocy in the processSection#data subs So, I'm wondering 1) is there a way baked in to .NET to have string.substring not error when reading past the end of a string without wrapping it in a try...catch? and 2) would it be appropriate in this situation to write a new string class that inherits from string that has a more friendly substring function in it? ETA: Thanks for all the advice and knowledge everyone. I'll go with the extension. Hopefully one of these years, I'll get my chops up enough to pay someone back in kind. :)

    Read the article

  • String.split() method bug in GWT 2.0.3

    - by Domchi
    I'm upgrading a GWT project from GWT 1.7.1 to currently newest version 2.0.3. It seems that new GWT broke String.split(String regex) method - I get the following error on the Javascript side: this$static is undefined This happens in this line of my .nocache.js file: if (maxMatch == 0 && this$static.length > 0) { ...which happens to be a part of String split method equivalent in Javascript. Is there a cure for this, apart from doing string splitting myself?

    Read the article

  • Print a string that contains a certain pattern in Java

    - by jjpotter
    I am trying to find a regular expression within a line of a .csv file, so I can eventually save all the matches to another file, and lose all the other junk. So a line in my file might look like: MachineName,User,IP,VariableData,Location The VariableData is what I want to match, and if there's a match, print the line. I am using a pattern for this because I only want 3 out of 10 of variations of VariableData, and out of those 3, they are numbered differently(example, "pc104, pccrt102, pccart65"). I am trying to do this using the Scanner Class and keeping it simple as possible so I can understand it. Here is where I was heading with this...(the pattern isn't complete, just have it like this for testing). import java.io.File; import java.util.Scanner; import java.util.regex.Pattern; public class pcv { public static void main(String[] args) { File myFile = new File("c:\\temp\\report.csv"); Pattern myPat = Pattern.compile("pc"); try{ Scanner myScan = new Scanner(myFile); while(myScan.hasNext()){ if(myScan.hasNext(myPat)){ System.out.println("Test"); } } }catch(Exception e){ } } } This code loops, im guessing the .hasNext() methods are resetting themselves. I've played around with the Matcher class a little bit, but only found a way to match the expression but not get the whole line. My other throught was maybe somehow count the line that contains the pattern, then go back and print the line that corresponds to the counts.

    Read the article

  • String manipulation of type String substitution in mathematical expression

    - by Peterstone
    Imagine something like exp(49/200)+(x-49/200) I want to pass as argument of the function "roundn" whatever operation that is not a addtion or a subtraction So my expresion became roundn(exp(roundn(49/200,n)),n)+(x - roundn(49/200,n) Well the expression I want to manipulate is this: exp(49/200)+exp(49/200)*(x-49/200)+1/2*exp(49/200)*(x-49/200)^2+1/6*exp(49/200)*(x- 49/200)^3+1/24*exp(49/200)*(x-49/200)^4+1/120*exp(49/200)*(x-49/200)^5+1/720*exp(49/200)*(x-49/200)^6+1/5040*exp(49/200)*(x-49/200)^7+1/40320*exp(49/200)*(x-49/200)^8+1/362880*exp(49/200)*(x-49/200)^9+1/3628800*exp(49/200)*(x-49/200)^10+1/39916800*exp(49/200)*(x-49/200)^11 I´m looking for a method (That include whatever program) not based in lenguage programming, as much batch or somithing like that... Thank you!

    Read the article

  • finding a string of random characters (with possible errors) within a large string of random charact

    - by mike
    I am trying to search a large string w/o spaces for a smaller string of characters. using regex I can easily find perfect matches but I can't figure out how to find partial matches. by partial matches i mean one or two extra characters in the string or one or two characters that have been changed, or one of each. the first and last characters will always match though. this would be similar to a spell checker but there are no spaces and the strings dont contain actual words, just random hex digits. i figured a way to find the string if there are no extra characters using indexOf(string.charAt(0)) and indexOf(charAt(string.length()-1) and looping through the characters between the two indexes. but this can be problematic when dealing with randomized characters because of the possibility of finding the first and last characters at the correct spacing but none of the middle characters matching. i've been scratching my head for hours on this issue. any ideas?

    Read the article

  • Java string too long?

    - by wrongusername
    I have the following code in Java (which worked just fine in C++ for some reason) which produces an error: int a; System.out.println("String length: " + input.length()); for(a = 0; ((a + 1) * 97) < input.length(); a++) { System.out.print("Substring at " + a + ": "); System.out.println(input.substring(a * 97, 97)); //other code here... } Output: String length: 340 Substring at 0: HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHe Substring at 1: Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: -97 //long list of "at ..." stuff Substring at 2: Using a string of length 200, however, the following output is produced: String length: 200 Substring at 0: HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHe Substring at 1: That is it; no exceptions raised, just... nothing. What is happening here?

    Read the article

  • Spotting similarities and patterns within a string - Python

    - by RadiantHex
    Hi folks, this is the use case I'm trying to figure this out for. I have a list of spam subscriptions to a service and they are killing conversion rate and other usability studies. The emails inserted look like the following: [email protected] [email protected] [email protected] roger[...]_surname[...]@hotmail.com What would be your suggestions on spotting these entries by using an automated script? It feels a little more complicated than it actually looks. Help would be very much appreciated!

    Read the article

  • How can we remove specific string from string ?

    - by Harikrishna
    I will have a different type of string(string will not have fixed format,they will be different every time) from them I want to remove some specific substring.Like the string can be FUTIDX 26FEB2009 NIFTY 0 FUTSTK ONGC 27 Mar 2008 FUTIDX MINIFTY 30 Jul 2009 FUTIDX NIFTY 27 Aug 2009 NIFTY FUT XP: 29/05/2008 Now I want to Remove the string which starts with FUT how can I do that ?

    Read the article

  • string.format vs + for string concatenatoin

    - by AMissico
    Which is better in respect to performance and memory utilization? // + Operator oMessage.Subject = "Agreement, # " + sNumber + ", Name: " + sName; // String.Format oMessage.Subject = string.Format("Agreement, # {0}, Name: {1}", sNumber, sName); My preference is memory utilization. The + operator is used throughout the application. String.Format and StringBuilder is rarely use. I want to reduce the amount of memory fragmentation caused by excessive string allocations.

    Read the article

  • How to compare two structure strings in C++

    - by Arvandor
    Ok, so this week in class we're working with arrays. I've got an assignment that wanted me to create a structure for an employee containing an employee ID, first name, last name, and wages. Then it has me ask users for input for 5 different employees all stored in an array of this structure, then ask them for a search field type, then a search value. Lastly, display all the information for all positive search results. I'm still new, so I'm sure it isn't a terribly elegant program, but what I'm trying to do now is figure out how to compare a user entered string with the string stored in the structure... I'll try to give all the pertinent code below. struct employee { int empid, string firstname, string lastname, float wage }; employee emparray[] = {}; employee value[] = {}; //Code for populating emparray and structure, then determine search field etc. cout << "Enter a search value: "; cin >> value.lastname; for(i = 0; i < 5; i++) { if(strcmp(value.lastname.c_str, emparray[i].lastname.c_str) == 0) { output(); } } Which... I thought would work, but it's giving me the following error.. Error 1 error C3867: 'std::basic_string<_Elem,_Traits,_Alloc>::c_str': function call missing argument list; use '&std::basic_string<_Elem,_Traits,_Alloc>::c_str' to create a pointer to member d:\myfile Any thoughts on what's going on? Is there a way to compare two .name notated strings without totally revamping the program? IF you want to drill me on best practices, please feel free, but also please try to solve my particular problem.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >