Search Results

Search found 82 results on 4 pages for 'substrings'.

Page 1/4 | 1 2 3 4  | Next Page >

  • Find all substrings of a string - StringIndexOutOfBoundsException

    - by nazar_art
    I created class Word. Word has a constructor that takes a string argument and one method getSubstrings which returns a String containing all substring of word, sorted by length. For example, if the user provides the input "rum", the method returns a string that will print like this: r u m ru um rum I want to concatenate the substrings in a String, separating them with a newline ("\n"). Then return the string. Code: public class Word { String word; public Word(String word) { this.word = word; } /** * Gets all the substrings of this Word. * @return all substrings of this Word separated by newline */ public String getSubstrings() { String str = ""; int i, j; for (i = 0; i < word.length(); i++) { for (j = 0; j < word.length(); j++) { str = word.substring(i, i + j); str += "\n"; } } return str; } But it throws exception: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1911) I stuck at this point. Maybe, you have other suggestions according this method signature public String getSubstrings(). How to solve this issue?

    Read the article

  • Clustering Strings on the basis of Common Substrings

    - by pk188
    I have around 10000+ strings and have to identify and group all the strings which looks similar(I base the similarity on the number of common words between any two give strings). The more number of common words, more similar the strings would be. For instance: How to make another layer from an existing layer Unable to edit data on the network drive Existing layers in the desktop Assistance with network drive In this case, the strings 1 and 3 are similar with common words Existing, Layer and 2 and 4 are similar with common words Network Drive(eliminating stop word) The steps I'm following are: Iterate through the data set Do a row by row comparison Find the common words between the strings Form a cluster where number of common words is greater than or equal to 2(eliminating stop words) If number of common words<2, put the string in a new cluster. Assign the rows either to the existing clusters or form a new one depending upon the common words Continue until all the strings are processed I am implementing the project in C#, and have got till step 3. However, I'm not sure how to proceed with the clustering. I have researched a lot about string clustering but could not find any solution that fits my problem. Your inputs would be highly appreciated.

    Read the article

  • Generate all unique substrings for given string

    - by Yuval A
    Given a string s, what is the fastest method to generate a set of all its unique substrings? Example: for str = "aba" we would get substrs={"a", "b", "ab", "ba", "aba"}. The naive algorithm would be to traverse the entire string generating substrings in length 1..n in each iteration, yielding an O(n^2) upper bound. Is a better bound possible? (this is technically homework, so pointers-only are welcome as well)

    Read the article

  • unique substrings using suffix tree

    - by user1708762
    For a given string S of length n- Optimal algorithm for finding all unique substrings of S can't be less than O(n^2). So, the best algorithm will give us the complexity of O(n^2). As per what I have read, this can be implemented by creating suffix tree for S. The suffix tree for S can be created in O(n) time. Now, my question is- How can we use the suffix tree for S to get all the unique substrings of S in O(n^2)?

    Read the article

  • iPhone colorize UILabel substrings

    - by Janosch R
    Hey, I’m parsing a twitter rss feed, and I just need to show tweets, so I don't need MGTwitterEngine. I have already set it up so I can see the complete tweet, the only thing I want it to colorize hashtags and urls. So I would need to slice up the string in different substrings, colorize the hashtags and urls and glue it together in various UILabels Is there an easier way to accomplish this? In short I need some parts of a string colored differently than others.

    Read the article

  • Finding partial substrings within a string

    - by Peter Chang
    I have two strings which must be compared for similarity. The algorithm must be designed to find the maximal similarity. In this instance, the ordering matters, but intervening (or missing) characters do not. Edit distance cannot be used in this case for various reasons. The situation is basically as follows: string 1: ABCDEFG string 2: AFENBCDGRDLFG the resulting algorithm would find the substrings A, BCD, FG I currently have a recursive solution, but because this must be run on massive amounts of data, any improvements would be greatly appreciated

    Read the article

  • find substrings inside string

    - by senzacionale
    How can i find substrings inside string and then remember and delete it when i found it. EXAMPLE: select * from (select a.iid_organizacijske_enote, a.sifra_organizacijske_enote "Sifra OE", a.naziv_organizacijske_enote "Naziv OE", a.tip_organizacijske_enote "Tip OE" I would like to get all word inside " ", so Sifra OE Naziv OE TIP OE and return select * from (select a.iid_organizacijske_enote, a.sifra_organizacijske_enote, a.naziv_organizacijske_enote, a.tip_organizacijske_enote i try with regex, indexOf() but no one works ok

    Read the article

  • Find all substrings between two strings

    - by Orsol
    I need to get all substrings from string. For ex: StringParser.GetSubstrings("[start]aaaaaa[end] wwwww [start]cccccc[end]", "[start]", "[end]"); that returns 2 string "aaaaaa" and "cccccc" Suppose we have only one level of nesting. Not sure about regexp, but I think it will be userful.

    Read the article

  • Java strings and substrings

    - by omaxgreen
    hey folks, Can someone help me with this Java problem? I want to write a method that takes two strings as arguments and returns true if each character (including space and punctuation) that appears in one string also appears in the other. Thanks

    Read the article

  • How to extract substrings with PHP

    - by shin
    PHP beginner's question. I need to keep image paths as following in the database for the admin backend. ../../../../assets/images/subfolder/myimage.jpg However I need image paths as follows for the front-end. assets/images/subfolder/myimage.jpg What is the best way to change this by PHP? I thought about substr(), but I am wondering if there is better ways. Thanks in advance.

    Read the article

  • Splitting input into substrings in PIG (Hadoop)

    - by Niels Basjes
    Assume I have the following input in Pig: some And I would like to convert that into: s so som some I've not (yet) found a way to iterate over a chararray in pig latin. I have found the TOKENIZE function but that splits on word boundries. So can "pig latin" do this or is this something that requires a Java class to do that?

    Read the article

  • Javascript substrings multiline replace by RegExp

    - by Radek Šimko
    Hi, I'm having some troubles with matching a regular expression in multi-line string. <script> var str="Welcome to Google!\n"; str = str + "We are proud to announce that Microsoft has \n"; str = str + "one of the worst Web Developers sites in the world."; document.write(str.replace(/.*(microsoft).*/gmi, "$1")); </script> http://jsbin.com/osoli3/3/edit As you may see on the link above, the output of the code looks like this: Welcome to Google! Microsoft one of the worst Web Developers sites in the world. Which means, that the replace() method goes line by line and if there's no match in that line, it returns just the whole line... Even if it has the "m" (multiline) modifier...

    Read the article

  • Substrings, timer and LED lights, as3

    - by VideoDnd
    How would I sync my timer with my LED lights? I don't understand how to to set up the strings and conditions, so that they are unique to each number space. Need a condition and values for each blinker var condition:Number = 5; if(condition==5){ blink.visible = !blink.visible; //blink_.visible = !box.visible; //blink__.visible = !box.visible; } } Complete code //MY TIMER var timer:Timer = new Timer(100); //INTEGER VALUES var count:int = 0; var fcount:int = 0; var oldcount:int = 0; //FORMATTING STRING function formatCount(i:int):String { var fraction:int = i % 100; var whole:int = i / 100; return ("00" + whole).substr(-2, 2) + "." + (fraction < 10 ? "0" + fraction : fraction); } //START TIMER timer.start(); timer.addEventListener(TimerEvent.TIMER, condition); //ANIMATION function condition(event:TimerEvent):void{ count++; fcount=int(count) var toText:String = formatCount(fcount); dec.text = toText.substr(4, 1); decimal.text = toText.substr(3, 1); ones.text = toText.substr(1, 1); //LED LIGHTS var condition:Number = 5; if(condition==5){ blink.visible = !blink.visible; //blink_.visible = !box.visible; //blink__.visible = !box.visible; } }

    Read the article

  • How to match multiple substrings in jQuery combobox autocomplete

    - by John R
    I found more than a couple examples of this with a plain jquery autocomplete but not in a way that will work with the autocomplete included in the combobox code from the demo because the structure of the code is structured so differently. I want to match every item that has all of the search tokens anywhere in any word. I don't need to match the start of any word, any part of it is fine. I don't care if the search strings are highlighted in the autocomplete list if that makes things too complicated. Desired search/result combos: (please excuse the spacing) "fi th" "fi rst second th ird" "rs on" "fi rs t sec on d third" "ec rd" "first s ec ond thi rd" but not limited to any max/min length or number of tokens. EDIT I figured part of it out using the code structure from the other autocorrect I had working. source: function( requestObj, responseFunc ) { var matchArry = $("select > option").map(function(){return this.innerHTML;}).get(); var srchTerms = $.trim(requestObj.term).split(/\s+/); // For each search term, remove non-matches $.each (srchTerms, function (J, term) { var regX = new RegExp (term, "i"); matchArry = $.map (matchArry, function (item) { if( regX.test(item) ){ return{ label: item, value: item, option: HTMLOptionElement } ? item :null; } } ); }); // Return the match results responseFunc (matchArry); }, and select: function( event, ui ) { ui.item.option.selected = true; self._trigger( "selected", event, { item: ui.item.option }); $("destination").val(ui.item.value); // I added this line }, but I can't get both multiple words AND being able to click to select working at the same time. If I remove the } ? item :null; on the return in the map function I can click to select an item. If I leave it I can type multiple words, but I can't click any of the items... Is that the problem or the option: this? I've tried replacing it with HTMLOptionElement and null and I'm stuck. I am able to set the value of another field with ui.item.value within the select label but that doesn't put the value in the search box or close the dropdown menu. Fiddle of current code: http://jsfiddle.net/eY3hM/

    Read the article

  • substrings and multiple textfields, AS3

    - by VideoDnd
    How do I get my text fields to populate correctly and show single digits? Description Each textfield receives a substring. This doesn't limit it's input, because the text fields shows extra numbers. The counters are set to 2,200,000.00, just to see if the numbers are populating. Ex A is the one I'm trying to fix. Ex A the one I want to fix //Tweening method 'could substitute code with Tweener' import fl.transitions.Tween; import fl.transitions.easing.*; //Timer that will run a sec and repeat var timer:Timer = new Timer(1000); //Integer values var count:int = +220000000; var fcount:int = 0; //Events and starting timer timer.addEventListener(TimerEvent.TIMER, incrementCounter); addEventListener(Event.ENTER_FRAME, checkOdometerPosition); timer.start(); //Tween Variables var smoothLoop:int = 0; var originalYPosition:Number = 0; var upwardYPosition:Number = -99; //Formatting String function formatCount(i:int):String { var fraction:int = i % 100; var whole:int = i / 100; return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction); } //First Digit function checkOdometerPosition(event:Event):void{ if (seconds9.y <= upwardYPosition){ var toText:String = formatCount(fcount); //seconds9.firstDigit.text = formatCount(fcount); seconds9.firstDigit.text = toText.substr(9, 9); seconds9.y = originalYPosition; seconds8.firstDigit.text = toText.substr(8, 8); seconds8.y = originalYPosition; seconds7dec.firstDigit.text = toText.substr(7, 7); seconds7dec.y = originalYPosition; seconds6.firstDigit.text = toText.substr(6, 6); seconds6.y = originalYPosition; seconds5.firstDigit.text = toText.substr(5, 5); seconds5.y = originalYPosition; seconds5.firstDigit.text = toText.substr(4, 4); seconds5.y = originalYPosition; seconds3.firstDigit.text = toText.substr(3, 3); seconds3.y = originalYPosition; seconds2.firstDigit.text = toText.substr(2, 2); seconds2.y = originalYPosition; seconds1.firstDigit.text = toText.substr(1, 1); seconds1.y = originalYPosition; seconds1.firstDigit.text = toText.substr(1, 1); seconds1.y = originalYPosition; seconds0.firstDigit.text = toText.substr(0, 1); seconds0.y = originalYPosition; } } //Second Digit function incrementCounter(event:TimerEvent):void{ count++; fcount=int(count) if (smoothLoop < 9){ smoothLoop++; } else { smoothLoop = 0; } var lolly:String = formatCount(fcount-1); //seconds9.secondDigit.text = formatCount(fcount); seconds9.secondDigit.text = lolly.substr(9, 9); var addTween9:Tween = new Tween(seconds9, "y", Strong.easeOut,0,-222, .7, true); seconds8.secondDigit.text = lolly.substr(8, 8); var addTween8:Tween = new Tween(seconds8, "y", Strong.easeOut,0,-222, .7, true); seconds7dec.secondDigit.text = lolly.substr(7, 7); var addTween7dec:Tween = new Tween(seconds7dec, "y", Strong.easeOut,0,-222, .7, true); seconds6.secondDigit.text = lolly.substr(6, 6); var addTween6:Tween = new Tween(seconds6, "y", Strong.easeOut,0,-222, .7, true); seconds5.secondDigit.text = lolly.substr(5, 5); var addTween5:Tween = new Tween(seconds5, "y", Strong.easeOut,0,-222, .7, true); seconds4.secondDigit.text = lolly.substr(4, 4); var addTween4:Tween = new Tween(seconds4, "y", Strong.easeOut,0,-222, .7, true); seconds3.secondDigit.text = lolly.substr(3, 3); var addTween3:Tween = new Tween(seconds3, "y", Strong.easeOut,0,-222, .7, true); seconds2.secondDigit.text = lolly.substr(2, 2); var addTween2:Tween = new Tween(seconds2, "y", Strong.easeOut,0,-222, .7, true); seconds1.secondDigit.text = lolly.substr(1, 1); var addTween1:Tween = new Tween(seconds1, "y", Strong.easeOut,0,-222, .7, true); seconds0.secondDigit.text = lolly.substr(0, 1); var addTween0:Tween = new Tween(seconds0, "y", Strong.easeOut,0,-222, .7, true); } Ex A has 10 text objects, each with a pair of text fields. It’s move complex than Ex B, because it has a Y animation and pairs of numbers. The text objects are animated to create a scrolling effect. It moves vertically, and has a lead number and a catch up number contained in each symbol. See illustration for more description. Ex B work fine! for example only //STRING SPLITTER COUNTER with nine individual text fields //Timer settings var delay:uint = 1000/100; var repeat:uint = 0; var timer:Timer; timer = new Timer(delay,repeat); timer.addEventListener(TimerEvent.TIMER, incrementCounter); timer.start(); //Integer values var count:int = 0; var fcount:int = 0; //Format Count function formatCount(i:int):String { var fraction:int = i % 100; var whole:int = i / 100; return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction); } //Split strings off to individual text fields function incrementCounter(event:TimerEvent) { count++; fcount=int(count+220000000) var toText:String = formatCount(fcount); mytext9.text = toText.substr(9, 9); mytext8.text = toText.substr(8, 8); mytext7dec.text = toText.substr(7, 7); mytext6.text = toText.substr(6, 6); mytext5.text = toText.substr(5, 5); mytext4.text = toText.substr(4, 4); mytext3.text = toText.substr(3, 3); mytext2.text = toText.substr(2, 2); mytext1.text = toText.substr(1, 1); mytext0.text = toText.substr(0, 1); }

    Read the article

  • What is an efficient way to erase substrings?

    - by Legend
    I have a long string and a set of <end-index, string> list like the following: long_sentence = "This is a long long long long sentence" indices = [[6, "is"], [8, "is a"], [18, "long"], [23, "long"]] An element 6, "is" indicates that 6 is the end index of the word "is" in the string. I want to get the following string in the end: >> print long_sentence This .... long ......... long sentence" I tried an approach like this: temp = long_sentence for i in indices: temp = temp[:int(i[0]) - len(i[1])] + '.'*(len(i[1])+1) + temp[i[0]+1:] While this seems to be working, it is taking exceptionally long time (more than 6 hours on 5000 strings inside a 300 MB file). Is there a way to speed this up?

    Read the article

  • finding long repeated substrings in a massive string

    - by Will
    I naively imagined that I could build a suffix trie where I keep a visit-count for each node, and then the deepest nodes with counts greater than one are the result set I'm looking for. I have a really really long string (hundreds of megabytes). I have about 1 GB of RAM. This is why building a suffix trie with counting data is too inefficient space-wise to work for me. To quote Wikipedia's Suffix tree: storing a string's suffix tree typically requires significantly more space than storing the string itself. The large amount of information in each edge and node makes the suffix tree very expensive, consuming about ten to twenty times the memory size of the source text in good implementations. The suffix array reduces this requirement to a factor of four, and researchers have continued to find smaller indexing structures. And that was wikipedia's comments on the tree, not trie. How can I find long repeated sequences in such a large amount of data, and in a reasonable amount of time (e.g. less than an hour on a modern desktop machine)? (Some wikipedia links to avoid people posting them as the 'answer': Algorithms on strings and especially Longest repeated substring problem ;-) )

    Read the article

  • How to keep same substrings in vim regex

    - by invisiblerhino
    Hi everyone. I'd ideally like a vim answer to this: I want to change [*, 1, *, *] to [*, 2, *, *] Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] If people know how to do this in perl or python or whatever, that would be equally good. Cheers

    Read the article

  • Fortran - String with unknown characters into substrings

    - by Masoud
    I am trying to put an input string into sub-string arrays. The number of data in the input file are less than 10 but unknown. The number of spaces between each data is also unclear. Example: Asd B Cwqe21 Ddsw Eww I am quite novice to Fortran, so I do not know which format I should use. My problem is that I do not know the number of data (here I assumed that there are 5), so how can I make the code work? I tried the following which did not work: CHARACTER (LEN=100), DIMENSION(10) :: string READ (1,*) (string,I=1,10) It seems that the error I got was because there was no 6th string to read and put into string(6). I tried using the "Index" to find the space, but since I do not know how many spaces are in the string, it did not help me.

    Read the article

  • Saving substrings using Regular Expressions

    - by user362971
    I'm new to regular expressions in Java (or any language, for that matter) and I'm wanting to do a find using them. The tricky part that I don't understand how to do is replace something inside the string that matches. For example, if the line I'm looking for is Person item6 [can {item thing [wrap]}] I'm able to write a regex that finds that line, but finding what the word "thing" is (as it may differ among different lines) is my problem. I may want to either replace that word with something else or save it in a variable for later. Is there any easy way to do this using Java's regex engine?

    Read the article

  • How can I detect common substrings in a list of strings

    - by danio
    Given a set of strings, for example: EFgreen EFgrey EntireS1 EntireS2 J27RedP1 J27GreenP1 J27RedP2 J27GreenP2 JournalP1Black JournalP1Blue JournalP1Green JournalP1Red JournalP2Black JournalP2Blue JournalP2Green I want to be able to detect that these are three sets of files: EntireS[1,2] J27[Red,Green]P[1,2] JournalP[1,2][Red,Green,Blue] Are there any known ways of approaching this problem - any published papers I can read on this? The approach I am considering is for each string look at all other strings and find the common characters and where differing characters are, trying to find sets of strings that have the most in common, but I fear that this is not very efficient and may give false positives. Note that this is not the same as 'How do I detect groups of common strings in filenames' because that assumes that a string will always have a series of digits following it. [Edited 15/09/09 to add more sample strings]

    Read the article

  • (PHP) - Changing two substrings inside a string

    - by Imp4ct
    This is my BIG string BEGIN:VEVENT UID:xxxxxx DTSTAMP:xxxxxx STATUS:CONFIRMED CLASS:PUBLIC URL:xxxxxx SUMMARY:YYYYYYY DESCRIPTION:xxxxxx; YYYYYYY; DTSTART:xxxxxx DTEND:xxxxxx GEO:xxxxxx LOCATION:xxxxxx END:VEVENT I need to change position of the two "YYYYYYY" in SUMMARY/DESCRIPTION I have to replace them without being specific since it is implemented in a much larger function. (This string is already sliced out of a 3700 line - Calendar) pls help! :)

    Read the article

  • Strange, regex.split Method matches one null element

    - by dontoo
    Regex rx = new Regex(@"[+-]"); string[] substrings = rx.Split(expression); expression = "-9a3dcbh-3bca-4ab4cf-3hc" //This is the iput string I want to split that string between + or -. My VS debugger shows substring array like this: substrings[0] = null //???Why substrings[1] = 9a3dcbh substrings[2] = 3bca substrings[3] = 4ab4cf substrings[4] = 3hc Why is the first element of arry null, is it because I am matching +-, and there is no + in my input string?

    Read the article

1 2 3 4  | Next Page >