Search Results

Search found 3864 results on 155 pages for 'split'.

Page 18/155 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • clever way to conditionally split this string?

    - by sprugman
    I've got a string that could be in one of two forms: prefix=key=value (which could have any characters, including '=') or key=value So I need to split it either on the first or second equals sign, based on a boolean that gets set elsewhere. I'm doing this: if ($split_on_second) { $parts = explode('=', $str, 3); $key = $parts[0] . '=' . $parts[1]; $val = $parts[2]; } else { $parts = explode('=', $str, 2); $key = $parts[0]; $val = $parts[1]; } Which should work, but feels inelegant. Got any better ideas in php? (I imagine there's a regex-ninja way to do it, but I'm not a regex-ninja.;-)

    Read the article

  • Split SQL statements

    - by eaZy
    Hello, I am writing a backend application which needs to be able to send multiple SQL commands to a MySQL server. MySQL = 5.x support multiple statements, but unfortunately we are interfacing with MySQL 4.x. I am trying to find a way (hint: regex) to split SQL statements by their semicolon, but it should ignore semicolons in single and double quotes strings. http://www.dev-explorer.com/articles/multiple-mysql-queries has a very nice regex to do that, but doesn't support double quotes. I'd be happy to hear your suggestions.

    Read the article

  • process the data after using str.split

    - by juju
    I parse a .txt like this: def parse_file(src): for line in src.readlines(): if re.search('SecId', line): continue else: cols = line.split(',') Time = cols[4] output_file.write('{}\n'.format( Time)) I think cols are lists that I could use index. Although it succeeds in printing out correct result as I want, there exists an out of range error. What's the matter? File "./tdseq.py", line 37, in parse_file Time = cols[4] IndexError: list index out of range make: *** [all] Error 1 Data I use: I10.FE,--,2008-04-16,15:15:00,13450,13488,13450,13470,490,359,16APR2008:09:15:00 I10.FE,--,2008-04-16,15:16:00,13468,13473.8,13467,13467,306,521,16APR2008:09:16:00 ....

    Read the article

  • Should I split this model and table?

    - by regedarek
    I would like to create simple ResumeBank app. Issue: As user I would like to add only two Resumes. Forms for this both Resumes are different with only two fields. Resumes have 12 the same attributes but 2 are diferent. Question: Should I split that Resume model and tables to ex: PolishResume and EnglishResume, polish_remsumes and english_remsumes? Or maybe should I use STI and create PolishResume < Resume and use one table. What are disadvantages of splitting option?

    Read the article

  • How to cut a URL with regular expression

    - by AhmadAssaf
    Hello, i am trying to chop a string that contains several information in java .. the text is something like that : <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a> i am thinking of using the .split method that need regular expression .. what i want it to split this string into the URL without quotes .. http://...... .com and then the text between the tags .. this case HootSuite .. i will appreciate the help Thank you

    Read the article

  • Get Specific part of a String in Javascript

    - by streetparade
    I have a string containing something like this "Hello bla bla bla bla ok, once more bla können. // this is static: it doesn't change This is a text, this also a text. // this is dynamically added text it can change each time My name mysurename // this is also static text www.blabla.com " Now I have content and I have to get the first part of the string and the third part, I want to be able to have 3 parts, I think I have to split it using something like split(); string1 = "Hello bla bla bla bla ok, once more bla können.; string2 = ""; // i have this part string3 ="My name mysurename"; If it helps the first part ends with "können. " and the third part ends with the url above // its a fictional URL

    Read the article

  • Splitting a string according to a delimiter when elements in the string can contain the delimiter

    - by Vivin Paliath
    I have a string that looks like this: "#Text() #SomeMoreText() #TextThatContainsDelimiter(#blah) #SomethingElse()" I'd like to get back [#Text(), #SomeMoreText(), #TextThatContainsDelimiter(#blah), #SomethingElse()] One way I thought about doing this was to require that the # to be escaped into \#, which makes the input string: "#Text() #SomeMoreText() #TextThatContainsDelimiter(\#blah) #SomethingElse()" I can then split it using /[^\\]#/ which gives me: [#Text(), SomeMoreText, TextThatContainsDelimiter(\#blah), SomethingElse()] The first element will contain # but I can strip it out. However, is there a cleaner way to do this without having to escape the #, and which ensures that the first element will not contain a #? Basically I'd like it to split by # only if the # is not enclosed by parentheses. My hunch is that since the # is context-sensitive and and regular expressions are only suited for context-free strings, this may not be the right tool. If so, would I have to write a grammar for this and roll my own parser/lexer?

    Read the article

  • Retain Delimiters when Splitting String

    - by JoeC
    Edit: OK, I can't read, thanks to Col. Shrapnel for the help. If anyone comes here looking for the same thing to be answered... print_r(preg_split('/([\!|\?|\.|\!\?])/', $string, null, PREG_SPLIT_DELIM_CAPTURE)); Is there any way to split a string on a set of delimiters, and retain the position and character(s) of the delimiter after the split? For example, using delimiters of ! ? . !? turning this: $string = 'Hello. A question? How strange! Maybe even surreal!? Who knows.'; into this array('Hello', '.', 'A question', '?', 'How strange', '!', 'Maybe even surreal', '!?', 'Who knows', '.'); Currently I'm trying to use print_r(preg_split('/([\!|\?|\.|\!\?])/', $string)); to capture the delimiters as a subpattern, but I'm not having much luck.

    Read the article

  • strsplit in R with metacharacter

    - by user1429852
    I have received a large amount of data where the delimiter is a backslash (obviously a bad choice). I'm processing it in R for computation, and having a hard time finding how to split the string since the backslash is a metacharacter. For example, a string would look like this: "1128\0019\XA5\E2R\366\00=15" and I want to split it along the "\" character, but when I run the strsplit command: strsplit(tempStr, "\") Error in strsplit(tempStr, "\") : invalid regular expression '\', reason 'Trailing backslash' When I try to used the "fixed" option, it does not run because it is expecting something after the backslash: strsplit(tempStr, "\", fixed = TRUE) Unfortunately, I can't preprocess the data with another program because the data is generated daily. Please help and thanks!

    Read the article

  • Java spliting strings

    - by N0b
    Hi I've got a Java problem. I'm trying split a string when ever a " " occurs, for example the sentence test abc. Then move the first letter in each word from first to last. I got the moving the letter to work on the original string using String text = JOptionPane.showInputDialog(null,"Skriv in en normal text:"); char firstLetter = text.charAt(0); normal = text.substring(1,text.length()+0) + firstLetter; So my question is how would I split the string then start moving the letters around in each part of the cut string? Thanks in advance

    Read the article

  • Process results of conditional split in SSIS

    - by Robert
    I have a Data Flow Task and am connecting to a database via an OLE DB Source component to extract data. This data feeds into a Conditional Split component to separate the data based on a simple expression. After the evaluation of this expression, the data will end up in either of two locations: LocationA or LocationB. Alright, I have that all set up and working properly. Once the data is separated into these two locations, additional processing is to be done on the records. Here's where I am stuck: I need the the processing of records in LocationA to occur before the processing of records in LocationB. Is there a way to set precedence of which tasks occur before others? If not, what is the best way to handle this? I was thinking I may need to write the data in LocationA and LocationB back out to the database and create a new data flow task in the control flow to handle the order of which these records must be dealt with. Any help is greatly appreciated!

    Read the article

  • Year split in Quarters using basic jQuery

    - by Alexander Corotchi
    Hi, I have a interesting question: I want to split the year into 4 quarters. What is the idea, A quarter can be different: The HTML Code: <div class="quarterBody"> <span>04-29-2010</span> <span>06-29-2010</span> <span>08-29-2010</span> </div> jQuery (javascript) is total wrong, I hope that w: $(document).ready(function(){ var quarter1 = to make interval (01-01-2010 to 03-31-2010); var quarter2 = to make interval (03-01-2010 to 06-31-2010); var quarter3 = to make interval (06-01-2010 to 09-31-2010); var quarter4 = to make interval (09-01-2010 to 12-31-2010); ... $(".quarterBody span").each(function(){ var date = Date.parse($(this).text()); //to apply some magic code $(this).addClass(quarterNumber); }); }); OUTPUT: <div class="quarterBody"> <span class="Quarter1">02-29-2010</span> <span class="Quarter2">04-29-2010</span> <span class="Quarter3">08-29-2010</span> ... </div> I know right now it is a stupid way, but I hope that somebody can help me, or suggest an idea how to do that in a better way!! Thanks!

    Read the article

  • text-area-text-to-be-split-with-conditions repeated

    - by desmiserables
    I have a text area wherein i have limited the user from entering more that 15 characters in one line as I want to get the free flow text separated into substrings of max limit 15 characters and assign each line an order number. This is what I was doing in my java class: int interval = 15; items = new ArrayList(); TextItem item = null; for (int i = 0; i < text.length(); i = i + interval) { item = new TextItem (); item.setOrder(i); if (i + interval < text.length()) { item.setSubText(text.substring(i, i + interval)); items.add(item); } else { item.setSubText(text.substring(i)); items.add(item); } } Now it works properly unless the user presses the enter key. Whenever the user presses the enter key I want to make that line as a new item having only that part as the subText. I can check whether my text.substring(i, i + interval) contains any "\n" and split till there but the problem is to get the remaining characters after "\n" till next 15 or till next "\n" and set proper order and subText.

    Read the article

  • Why does Email::MIME split up my attachment?

    - by sid_com
    Why does the attachment(ca. 110KiB) split up in 10 parts(ca. 11KiB) when I send it with this script using Email::MIME? #!/usr/bin/env perl use warnings; use strict; use Email::Sender::Transport::SMTP::TLS; my $mailer = Email::Sender::Transport::SMTP::TLS->new( host => 'smtp.my.host', port => 587, username => 'username', password => 'password', ); use Email::MIME::Creator; use IO::All; my @parts = ( Email::MIME->create( attributes => { content_type => 'text/plain', disposition => 'inline', encoding => 'quoted-printable', charset => 'UTF-8', }, body => "Hello there!\n\nHow are you?", ), Email::MIME->create( attributes => { filename => "test.jpg", content_type => "image/jpeg", disposition => 'attachment', encoding => "base64", name => "test.jpg", }, body => io( "test.jpg" )->all, ), ); my $email = Email::MIME->create( header => [ From => 'my@address', To => 'your@address', Subject => 'subject', ], parts => [ @parts ], ); eval { $mailer->send( $email, { from => 'my@address', to => [ 'your@address' ], } ); }; die "Error sending email: $@" if $@;

    Read the article

  • why does b'(and sometimes b' ') show up when I split some HTML source[Python]

    - by Oliver
    I'm fairly new to Python and programming in general. I have done a few tutorials and am about 2/3 through a pretty good book. That being said I've been trying to get more comfortable with Python and proggramming by just trying things in the std lib out. that being said I have recently run into a wierd quirk that I'm sure is the result of my own incorrect or un-"pythonic" use of the urllib module(with Python 3.2.2) import urllib.request HTML_source = urllib.request.urlopen(www.somelink.com).read() print(HTML_source) when this bit is run through the active interpreter it returns the HTML source of somelink, however it prefixes it with b' for example b'<HTML>\r\n<HEAD> (etc). . . . if I split the string into a list by whitespace it prefixes every item with the b' I'm not really trying to accomplish something specific just trying to familiarize myself with the std lib. I would like to know why this b' is getting prefixed also bonus -- Is there a better way to get HTML source WITHOUT using a third party module. I know all that jazz about not reinventing the wheel and what not but I'm trying to learn by "building my own tools" Thanks in Advance!

    Read the article

  • c# regex split and extract multiple parts from a string

    - by nLL
    Hi, I am trying to extract some parts of the "Video:" line from below text. Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (300 00/1) - 14.93 (1000/67) Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\a.3gp': Metadata: major_brand : 3gp5 minor_version : 0 compatible_brands: 3gp5isom Duration: 00:00:45.82, start: 0.000000, bitrate: 357 kb/s Stream #0.0(und): Video: mpeg4, yuv420p, 352x276 [PAR 1:1 DAR 88:69], 344 kb /s, 14.93 fps, 14.93 tbr, 90k tbn, 30k tbc Stream #0.1(und): Audio: aac, 16000 Hz, mono, s16, 11 kb/s Stream #0.2(und): Data: mp4s / 0x7334706D, 0 kb/s Stream #0.3(und): Data: mp4s / 0x7334706D, 0 kb/s* This is an output from ffmpeg command line where i can get Video: part with private string ExtractVideoFormat(string rawInfo) { string v = string.Empty; Regex re = new Regex("[V|v]ideo:.*", RegexOptions.Compiled); Match m = re.Match(rawInfo); if (m.Success) { v = m.Value; } return v; } and result is mpeg4, yuv420p, 352x276 [PAR 1:1 DAR 88:69], 344 kb What i am trying to do is to somehow split that line and get mpeg4 yuv420p 352x276 [PAR 1:1 DAR 88:69] 344 kb assigned to diffrent string objects instead of single

    Read the article

  • Table cell in a split-view controller - selected cell becomes deselected when called by reloadData

    - by bpapa
    I'm working on a universal app that uses a SplitViewController to present a master-detail view. In the iPad HIG on Split Views, Apple states: In general, indicate the current selection in the left pane in a persistent way. This behavior helps people understand the relationship between the item in the left pane and the contents of the right pane. This is important because the contents of the right pane can change, but they should always remain related to the item selected in the left pane. So I'm trying to maintain selection state on the left. Easy enough when the user taps, I just remove the deselectRowAtIndexPath:animated: message from tableView:didSelectRowAtIndexPath: implementation. But, I also want the selection state to show up by default (without a user tap). I wound up putting this in my tableView:cellForRowAtIndexPath: implementation: if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if (cellShouldBeSelected) cell.selected = YES; else cell.selected = NO; } The behavior I'm seeing, is that when the cells finall appear, for a fraction of a section the cell is indeed selected, but then the selection disappears without any user interaction. Any ideas? I set the new clearsSelectionOnViewWillAppear property to NO, but that doesn't seem to fix it, and it shouldn't really matter because I'm marking the cell as selected long after viewWillAppear is called - I'm actually doing it after some network activity and then sending the table view a reloadData message.

    Read the article

  • regex split and extract multiple parts from a string

    - by nLL
    I am trying to extract some parts of the "Video:" line from below text. Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (300 00/1) -> 14.93 (1000/67) Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\a.3gp': Metadata: major_brand : 3gp5 minor_version : 0 compatible_brands: 3gp5isom Duration: 00:00:45.82, start: 0.000000, bitrate: 357 kb/s Stream #0.0(und): Video: mpeg4, yuv420p, 352x276 [PAR 1:1 DAR 88:69], 344 kb /s, 14.93 fps, 14.93 tbr, 90k tbn, 30k tbc Stream #0.1(und): Audio: aac, 16000 Hz, mono, s16, 11 kb/s Stream #0.2(und): Data: mp4s / 0x7334706D, 0 kb/s Stream #0.3(und): Data: mp4s / 0x7334706D, 0 kb/s* This is an output from ffmpeg command line where i can get Video: part with private string ExtractVideoFormat(string rawInfo) { string v = string.Empty; Regex re = new Regex("[V|v]ideo:.*", RegexOptions.Compiled); Match m = re.Match(rawInfo); if (m.Success) { v = m.Value; } return v; } and result is mpeg4, yuv420p, 352x276 [PAR 1:1 DAR 88:69], 344 kb What i am trying to do is to somehow split that line and get mpeg4 yuv420p 352x276 [PAR 1:1 DAR 88:69] 344 kb assigned to different string objects instead of single

    Read the article

  • SQL statement to split a table based on a join

    - by williamjones
    I have a primary table for Articles that is linked by a join table Info to a table Tags that has only a small number of entries. I want to split the Articles table, by either deleting rows or creating a new table with only the entries I want, based on the absence of a link to a certain tag. There are a few million articles. How can I do this? Not all of the articles have any tag at all, and some have many tags. Example: table Articles primary_key id table Info foreign_key article_id foreign_key tag_id table Tags primary_key id It was easy for me to segregate the articles that do have the match right off the bat, so I thought maybe I could do that and then use a NOT IN statement but that is so slow running it's unclear if it's ever going to finish. I did that with these commands: INSERT INTO matched_articles SELECT * FROM articles a LEFT JOIN info i ON a.id = i.article_id WHERE i.tag_id = 5; INSERT INTO unmatched_articles SELECT * FROM articles a WHERE a.id NOT IN (SELECT m.id FROM matched_articles m); If it makes a difference, I'm on Postgres.

    Read the article

  • split all text inside dom element into <span>

    - by gruber
    I would like to split all elements inside html DOM node into spans with ids, for example: lets say I have element: <div> <h1>Header</h1> <h2>header2</h2> <p class="test">this is test p</p> </div> and the result should be: <div> <h1><span id="1">Header</span></h1> <h2><span id="2">header2</span></h2> <p class="test"><span id="3">this</span><span id="4">is</span><span id="5">test</span> <span id="6">p</span></p> </div> thanks for any help it shoul also work if there are nested images for example: <div> <h1>Header</h1> <h2>header2</h2> <p class="test"><img alt="test alt" />this is test p</p> </div> and the result: <div> <h1><span id="1">Header</span></h1> <h2><span id="2">header2</span></h2> <p class="test"><img alt="test alt" /><span id="3">this</span><span id="4">is</span><span id="5">test</span> <span id="6">p</span></p> </div>

    Read the article

  • Files under Program Files have a split personality

    - by regularfry
    I have a Ruby application I'm installing (along with a packaged ruby interpreter) under Program Files on Windows 7 with an NSIS-built installer. In order to debug it, I edited one of the files to add some debugging statements. After that, I uninstalled the package and ran a new version of the installer which includes a new copy of the edited file, without debugging statements. Now, I can't get the new copy to load into ruby. If I run type <filename> in cmd.exe, or open the file in Notepad.exe or Firefox, I see the new version. If I run ruby -e "puts File.read('<filename>')", or open the file in emacs, I see the old version. If, in Windows Explorer, I copy the file to a new filename, everything can see the new contents at that filename. If I delete the original file and rename the copy to replace the original, the split personality returns. This situation survives a reboot, so it's not a simple matter of a file being accidentally held open. What on earth is going on here? Is there some aspect of the install process that might be checkpointing the file in a way I can revert, or at least switch off while I'm debugging the installer?

    Read the article

  • explode is not working to split string

    - by pmms
    we unable to split the string following code.please Help us. <?php $i=0; $myFile = "testFile.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = "no\t"; fwrite($fh, $stringData); $stringData = "username \t"; fwrite($fh, $stringData); $stringData ="password \t"; fwrite ($fh,$stringData); $newline ="\r\n"; fwrite ($fh,$newline); $stringData1 = "1\t"; fwrite($fh, $stringData1); $stringData1 = "srinivas \t"; fwrite($fh, $stringData1); $stringData1 ="malayappa \t"; fwrite ($fh,$stringData1); fclose($fh); ?> $fh = fopen("testFile.txt", "r"); $ while (!feof($fh)) { $line = fgets($fh); echo $line; } fclose($fh); $Beatles = array('pmm','malayappa','sreenivas','PHP'); for($i=0;$i<count($Beatles);$i++) { if($i==2) { echo $Beatles[$i-1]; echo $Beatles[$i-2]; } } $pass_ar=array(); $fh = fopen("testFile.txt", "r"); while (!feof($fh)) { $line = fgets($fh); echo $line; $t1=explode(" ",$line); print_r($t1); array_push($pass_ar,t1); } fclose($fh); Thanks & Regards pmms

    Read the article

  • How can I split abstract testcases in JUnit?

    - by Willi Schönborn
    I have an abstract testcase "AbstractATest" for an interface "A". It has several test methods (@Test) and one abstract method: protected abstract A unit(); which provides the unit under testing. No i have multiple implementations of "A", e.g. "DefaultA", "ConcurrentA", etc. My problem: The testcase is huge (~1500 loc) and it's growing. So i wanted to split it into multiple testcases. How can organize/structure this in Junit 4 without the need to have a concrete testcase for every implementation and abstract testcase. I want e.g. "AInitializeTest", "AExectueTest" and "AStopTest". Each being abstract and containing multiple tests. But for my concrete "ConcurrentA", i only want to have one concrete testcase "ConcurrentATest". I hope my "problem" is clear. EDIT Looks like my description was not that clear. Is it possible to pass a reference to a test? I know parameterized tests, but these require static methods, which is not applicable to my setup. Subclasses of an abstract testcase decide about the parameter.

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >