string-parsing

How to read formatted data in C++?

余生颓废 提交于 2019-11-30 13:12:55
问题 I have formatted data like the following: Words 5 AnotherWord 4 SomeWord 6 It's in a text file and I'm using ifstream to read it, but how do I separate the number and the word? The word will only consist of alphabets and there will be certain spaces or tabs between the word and the number, not sure of how many. 回答1: Assuming there will not be any whitespace within the "word" (then it will not be actually 1 word), here is a sample of how to read upto end of the file: std::ifstream file("file

Grabbing hidden inputs as a string (Using PHP Simple HTML DOM Parser)

倖福魔咒の 提交于 2019-11-30 04:34:52
问题 So I have a form that has 4 inputs, 2 text, 2 hidden. I've grabbed the two text input values from the name, which are (get_me_two, get_me_three) and I've also grabbed the form action which is (get_me.php). What I'm looking to do now is grab the 2 hidden inputs, but not the values. I want to grab the inputs themselves. E.G: Here's my form: <form action="get_me.php" method="post"> <input type="text" name="get_me_two"> <input type="text" name="get_me_three"> <input type="hidden" name="meta

Parse ISO timestamp using Java 8 java.time api (standard edition only)

為{幸葍}努か 提交于 2019-11-30 01:28:15
问题 I'm having trouble getting milliseconds from the epoch out of the string in the example. I have tried this three different ways so far, and the example shows the latest attempt. It always seems to come down to that the TemporalAccessor does not support ChronoField. If I could successfully construct an instance of Instant, I could use toEpochMilli(). String dateStr = "2014-08-16T05:03:45-05:00" TemporalAccessor creationAccessor = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(dateStr); Instant

How safe is SymPy's sympify(<string>).evalf()?

随声附和 提交于 2019-11-29 19:56:50
问题 We know Python's eval() is evil http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html and threads throughout StackOverflow suggest to use SymPy's evalf() . As a Python newbie, I can't really convince myself that evalf() is safe as I lack the skills. Can anyone elaborate on what evalf() does (different)? 回答1: There is nothing common between python eval and sympy evalf (the latter is for calculating the numeric value of sympy expression trees and it has nothing to do with parsing,

Parsing non-standard JSON

不羁岁月 提交于 2019-11-29 15:40:53
Anyone know what type of JSON (if even that!) the following code is? I'm retrieving this from the HTML of a website. I'm trying to parse it in C# with a JSON parser, but I'm having to do lots of preparatory editing to format it as 'valid' JSON according to JSONLint. For example, the names of the variables should all have double quotes rather than having no quotes at all. { status: 'A', displayed: 'Y', start_time: '2010-11-2600: 00: 00', start_time_xls: { en: '26thofNov201000: 00am', es: '26Nov201000: 00am' }, suspend_at: '2010-11-2619: 57: 59', is_off: 'Y', score_home: '', score_away: '', bids

java generic String to <T> parser

核能气质少年 提交于 2019-11-29 10:05:55
Is there a straight-forward way to implement a method with the following signature? At minimum, the implementation would need to handle primitive types (e.g. Double and Integer). Non-primitive types would be a nice bonus. //Attempt to instantiate an object of type T from the given input string //Return a default value if parsing fails static <T> T fromString(String input, T defaultValue) Implementation would be trivial for objects that implemented a FromString interface (or equivalent), but I haven't found any such thing. I also haven't found a functional implementation that uses reflection.

Javascript math parser library

浪尽此生 提交于 2019-11-29 04:09:09
Is there a good math parser in Javascript? I want to be able to parse something like: LOG(3.14)+5^2+POW(2,LN(X*2,Y)) Thanks, Here is a brand new initiative: http://mathjs.org Comes with an extensive and easy to use parser which also supports assignment and usage of variables and functions like in your example expression. Use this one. It defined an "operator" object that lets you define your own operators. http://jsfromhell.com/classes/math-processor Warning: it uses with . If you don't know why that's dangerous, find out before using this code in anything critical. Alternately, you could just

Long.getLong() failing, returning null to valid string

送分小仙女□ 提交于 2019-11-29 02:51:14
I've spent the past two hours debugging what seems extremely unlikely. I've stripped the method of a secondary Android Activity to exactly this: public void onClick(View v) { String str = "25"; long my_long = Long.getLong(str); } // onClick (v) And yeah, I get a crash with the good ol' NullPointerException: 09-11 02:02:50.444: ERROR/AndroidRuntime(1588): Uncaught handler: thread main exiting due to uncaught exception 09-11 02:02:50.464: ERROR/AndroidRuntime(1588): java.lang.NullPointerException It looks like (from other tests) that Long.getLong(str) returns NULL, which is driving me bonkers.

In JavaScript / jQuery what is the best way to convert a number with a comma into an integer?

笑着哭i 提交于 2019-11-29 01:12:21
I want to convert the string "15,678" into a value 15678. Methods parseInt() and parseFloat() are both returning 15 for "15,678." Is there an easy way to do this? The simplest option is to remove all commas: parseInt(str.replace(/,/g, ''), 10) paxdiablo One way is to remove all the commas with: strnum = strnum.replace(/\,/g, ''); and then pass that to parseInt: var num = parseInt(strnum.replace(/\,/g, ''), 10); But you need to be careful here. The use of commas as thousands separators is a cultural thing. In some areas, the number 1,234,567.89 would be written 1.234.567,89 . If you only have

How do I search for a pattern within a text file using Python combining regex & string/file operations and store instances of the pattern?

别等时光非礼了梦想. 提交于 2019-11-28 17:23:53
问题 So essentially I'm looking for specifically a 4 digit code within two angle brackets within a text file. I know that I need to open the text file and then parse line by line, but I am not sure the best way to go about structuring my code after checking "for line in file". I think I can either somehow split it, strip it, or partition, but I also wrote a regex which I used compile on and so if that returns a match object I don't think I can use that with those string based operations. Also I'm