string-parsing

No Member named stoi in namespace std

喜你入骨 提交于 2019-12-01 17:03:57
问题 I am testing out std::stoi function found in the link below: http://en.cppreference.com/w/cpp/string/basic_string/stol but I got the error: No Member named stoi in namespace std. What should I do? Please advise thanks. P.S: I am using Xcode Ide to do my c++. #include <iostream> #include <string> int main() { std::string test = "45"; int myint = std::stoi(test); std::cout << myint << '\n'; } Image 回答1: First of all, you need a compiler that supports C++11 and you need to compile in "C++11 mode

Convert a string with mathematical expressions into a float

牧云@^-^@ 提交于 2019-12-01 14:27:22
A text field contains mathematical expressions like: 12+45-6 Is possible to convert this string to a number? Can we use the predicate facility? NSString *foo = @"((a*b)/c+(d/5))+15"; // dummy predicate that contains our expression NSPredicate *pred = [NSPredicate predicateWithFormat:[foo stringByAppendingString:@" == 42"]]; NSExpression *exp = [pred leftExpression]; NSNumber *result = [exp expressionValueWithObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:4], @"a",[NSNumber numberWithInt:7], @"b",[NSNumber numberWithInt:2], @"c",[NSNumber numberWithInt:20], @"d",nil

Convert a string with mathematical expressions into a float

跟風遠走 提交于 2019-12-01 13:12:34
问题 A text field contains mathematical expressions like: 12+45-6 Is possible to convert this string to a number? Can we use the predicate facility? NSString *foo = @"((a*b)/c+(d/5))+15"; // dummy predicate that contains our expression NSPredicate *pred = [NSPredicate predicateWithFormat:[foo stringByAppendingString:@" == 42"]]; NSExpression *exp = [pred leftExpression]; NSNumber *result = [exp expressionValueWithObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:4], @"a",

Parsing quoted text in java

两盒软妹~` 提交于 2019-12-01 05:44:20
Is there an easy way to parse quoted text as a string to java? I have this lines like this to parse: author="Tolkien, J.R.R." title="The Lord of the Rings" publisher="George Allen & Unwin" year=1954 and all I want is Tolkien, J.R.R.,The Lord of the Rings,George Allen & Unwin, 1954 as strings. You could either use a regex like "(.+)" It will match any character between quotes. In Java would be: Pattern p = Pattern.compile("\\"(.+)\\""; Matcher m = p.matcher("author=\"Tolkien, J.R.R.\""); while(matcher.find()){ System.out.println(m.group(1)); } Note that group(1) is used, this is the second

How to use `strtoul` to parse string where zero may be valid?

旧时模样 提交于 2019-12-01 05:25:31
According to the documentation for strtoul , regarding its return value... This function returns the converted integral number as a long int value. If no valid conversion could be performed, a zero value is returned. What if I'm parsing a user-supplied string of "0" where, for my application, "0" may be a valid entry? In that case it seems that I have no way to determine from using strtoul if a valid conversion was performed. Is there another way to handle this? How to use strtoul to parse string where zero may be valid? Any value returned from strtoul() may be from an expected string input or

Parsing quoted text in java

不羁的心 提交于 2019-12-01 04:06:18
问题 Is there an easy way to parse quoted text as a string to java? I have this lines like this to parse: author="Tolkien, J.R.R." title="The Lord of the Rings" publisher="George Allen & Unwin" year=1954 and all I want is Tolkien, J.R.R.,The Lord of the Rings,George Allen & Unwin, 1954 as strings. 回答1: You could either use a regex like "(.+)" It will match any character between quotes. In Java would be: Pattern p = Pattern.compile("\\"(.+)\\""; Matcher m = p.matcher("author=\"Tolkien, J.R.R.\"");

How to use `strtoul` to parse string where zero may be valid?

淺唱寂寞╮ 提交于 2019-12-01 03:50:10
问题 According to the documentation for strtoul , regarding its return value... This function returns the converted integral number as a long int value. If no valid conversion could be performed, a zero value is returned. What if I'm parsing a user-supplied string of "0" where, for my application, "0" may be a valid entry? In that case it seems that I have no way to determine from using strtoul if a valid conversion was performed. Is there another way to handle this? 回答1: How to use strtoul to

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

ぃ、小莉子 提交于 2019-11-30 20:04:39
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_required" value="from"> <input type="hidden" name="meta_forward_vars" value="0"> </form> And what I want to

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

橙三吉。 提交于 2019-11-30 17:41:07
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 creationDate = Instant.from(creationAccessor); Please give concise answers (don't construct a

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

梦想的初衷 提交于 2019-11-30 13:58:28
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)? 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, while eval is all about parsing a string and evaluating it as if it is code). On the other hand, sympify is