string-parsing

Code to parse user agent string?

大憨熊 提交于 2019-12-17 09:47:21
问题 As strange as I find this, I have not been able to find a good PHP function anywhere which will do an intelligent parse of a user agent string? Googled it for about 20 minutes now. I have the string already, I just need something that will chop it up and give me at least browser/ver/os. Know of a good snippet anywhere? 回答1: The get_browser() function has been available in PHP for quite a long a time. The PHP manual is free, can be downloaded in various formats and viewed online (with comments

How do I parse a URL query parameters, in Javascript? [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-17 02:28:45
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Use the get paramater of the url in javascript How can I get query string values in JavaScript? In Javascript, how can I get the parameters of a URL string (not the current URL)? like: www.domain.com/?v=123&p=hello Can I get "v" and "p" in a JSON object? 回答1: Today (2.5 years after this answer) you can safely use Array.forEach . As @ricosrealm suggests, decodeURIComponent was used in this function. function

Workaround for this calculator parsing error

假如想象 提交于 2019-12-14 03:24:32
问题 Context : I entered a expression 3.24 * 10^10 + 1 into a calculator that I made. My calculator's approach to solve this is - it first looks for pattern number_a^number_b , parses the 2 numbers into double using Double.parseDouble() method, then performs Math.pow(number_a, number_b) and replaces the expression with the result. The calculator, then, similarly looks for pattern number_a * number_b and parses it. So far our expression becomes 3.24E10 + 1 . Now comes the tricky part. When I

How to fetch column names from 'MySQL Create Table' Query string?

拈花ヽ惹草 提交于 2019-12-13 17:03:09
问题 I want to write a script in PHP which get 'MySQL Create Table' Query as string and store column names and their data types in array. For example: input string: CREATE TABLE `test` ( `col1` INT( 10 ) NOT NULL , `col2` VARCHAR( 50 ) NOT NULL , `col3` DATE NOT NULL ) ENGINE = MYISAM ; output: array( array( 'name'=>'col1', 'type'=>'INT', 'size'=>'10' ), array( 'name'=>'col2', 'type'=>'VARCHAR', 'size'=>'50' ), array( 'name'=>'col3', 'type'=>'DATE', 'size'=>'' ) ); I don't have database access to

C - string to uint64_t casting with error handling

帅比萌擦擦* 提交于 2019-12-13 09:52:26
问题 This program is to cast strings to uint64_t types and get the errors if any. It should output, in this case, 2 errors (overflow and negative number), none of which appear. Also, it doesn't properly cast one of the strings. Any help would be appreciated. #include <stdio.h> #include <stdlib.h> #include <inttypes.h> #include <errno.h> #include <limits.h> int func(const char *buff) { char *end; int si; errno = 0; const uint64_t sl = strtoull(buff, &end, 10); if (end == buff) { fprintf(stderr, "%s

Split string into columns based on distance between values

好久不见. 提交于 2019-12-13 07:39:27
问题 I am working with unstructured text data exported from a PDF. The original data comes from a table in the PDF that was converted to text format, so all that remains is the general structure of it. A particular section I'm looking at used to be a table. So for example, here is some sample input A B C D E 1 2 3 4 6 7 The first line indicates the headers, and the following lines are the values. Fortunately, the spacing is preserved (somewhat): there will always be at least two spaces between

Sax parser read a line not totally

旧城冷巷雨未停 提交于 2019-12-13 00:09:02
问题 I'm trying to parse a simil-InkML document. Every content's node has more tuple (separated by comma) with 6 or 7 number (negative and decimal too). In testing I see that the method character of SAX don't memorize all the data. The code: public class PenParser extends DefaultHandler { //code useless public void characters(char ch[], int start, int length) throws SAXException { //begin my debug print StringBuilder buffer=new StringBuilder (); for(int i=start;i<length;i++){ buffer.append(ch[i]);

Is there an inverse of Common Lisp's FORMAT?

二次信任 提交于 2019-12-12 13:02:04
问题 I have a question that's been bothering me for some time. Is the Common Lisp format function reversible (at least to some degree) in that the format string could be used to retrieve original arguments from format 's output? I am aware that the mapping is not one-to-one (one example is the ~@:(~a~) which turns input to uppercase and is not reversible), so necessarily some information is lost. What I have in mind exactly is rather an alternative to regular expressions for string parsing. For

Parsing / Extracting Text from String in Rails?

。_饼干妹妹 提交于 2019-12-12 09:14:35
问题 I have a string in Rails, e.g. "This is a Twitter message. #books War & Peace by Leo Tolstoy. I love this book!", and I want to parse the text and extract only certain phrases, like "War & Peace by Leo Tolstoy". Is this a matter of using Regex and lifting the text between "#books" to "."? What if there's no structure to the message, like: "This is a Twitter message #books War & Peace by Leo Tolstoy I love this book!" or "This is a Twitter message. I love the book War & Peace by Leo Tolstoy

Cleanest data structure to use when interpreting data from neatly-structured user commands (in C++) [closed]

我与影子孤独终老i 提交于 2019-12-12 06:46:30
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I would like to write a simple in-house program that parses user commands written in a language of our team's own invention (but based closely on another program we are already familiar with). The command parser that I am working on now will simply be the UI through which the user