string-parsing

How to interpret numbers correctly (hex, oct, dec)

江枫思渺然 提交于 2019-12-06 12:52:45
问题 I'm trying to write a program that takes input of - hexadecimals, octals, and decimals -, stores them in integer variables, and outputs them along with their conversion to decimal form. For example: User inputs: 0x43, 0123, 65 Program outputs: 0x43 hexadecimal converts to 67 decimal 0123 octal converts to 83 decimal 65 decimal converts to 65 decimal So obviously I need a way to interpret the numbers, but I'm not sure how to go about doing it. I've tried various methods such as reading them

Using Java remove unbalanced/unpartnered parenthesis

若如初见. 提交于 2019-12-06 11:29:18
问题 I want to remove all the "unpartnered" or unpaired parenthesises from a string. exampleStr = back-pay) zyzhk1219(17) zyzhk1329 zyzhk1595(15) zyzhk1988 zyzhk2004 zyzhk2131) jswioj((testsjkldf The expected "parenthesis balanced" string should be back-pay zyzhk1219(17) zyzhk1329 zyzhk1595(15) zyzhk1988 zyzhk2004 zyzhk2131 jswiojtestsjkldf I saw some ruby based solution on stackoverflow. But, couldn't find one I can use in java. 回答1: How it might be done in pseudo-code: initialize parenLevel = 0

How to work with data from NBA.com?

流过昼夜 提交于 2019-12-06 11:18:16
I found Greg Reda's blog post about scraping HTML from nba.com : http://www.gregreda.com/2015/02/15/web-scraping-finding-the-api/ I tried to work with the code he wrote there: import requests import json url = 'http://stats.nba.com/stats/leaguedashteamshotlocations?Conference=&DateFr' + \ 'om=&DateTo=&DistanceRange=By+Zone&Division=&GameScope=&GameSegment=&LastN' + \ 'Games=0&LeagueID=00&Location=&MeasureType=Opponent&Month=0&OpponentTeamID' + \ '=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerExperien' + \ 'ce=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2014-15&SeasonSegment=

Extract data between two delimiters

為{幸葍}努か 提交于 2019-12-06 10:36:39
I just want to know whether it is possible to pick up the data that is present between two delimiters (delimiter being a string). For example the original string is as under <message%20type%3D"info"%20code%3D"20005">%20<text>Conference%20successfully%20modified</text>%20<data>0117246</data>%20%20</message>%20 and I want the data that is present between <text> tags. The string from which i need the data can be different. The string can also be like this <message%20type%3D"info"%20code%3D"20001">%20<text>Conference%20deleted</text%20%20<vanity>0116976</vanity>%20</message>%20<message%20type%3D

Parse hour and AM/PM value from a string - C#

巧了我就是萌 提交于 2019-12-06 07:26:17
What would be the most effective way to parse the hour and AM/PM value from a string format like "9:00 PM" in C#? Pseudocode: string input = "9:00 PM"; //use algorithm //end result int hour = 9; string AMPM = "PM"; ChaosPandion Try this: string input = "9:00 PM"; DateTime result; if (!DateTime.TryParse(input, out result)) { // Handle } int hour = result.Hour == 0 ? 12 : result.Hour <= 12 ? result.Hour : result.Hour - 12; string AMPM = result.Hour < 12 ? "AM" : "PM"; Try this: DateTime result; string input = "9:00 PM"; //use algorithm if (DateTime.TryParseExact(input, "h:mm tt", CultureInfo

Parsing a Connection String

拈花ヽ惹草 提交于 2019-12-05 22:04:41
Is there a standard library or code snippet to get a value with a connection string like this? string connstr = "DataServiceUrl=http://localhost/foo;" + "RemoteServerConnection={server=http://localhost/foo2;interface=0.0.0.0;};" + "publisherport=1234;StatisticsURL=http://localhost/foo3"; The whole inner connection property is kind of throwing this in a loop. I'd like to get specific values based on a key. Here was the answer posted by John I used: System.Data.Odbc.OdbcConnectionStringBuilder builder = new System.Data.Odbc.OdbcConnectionStringBuilder(); builder.ConnectionString = this

Python. Join specific lines on 1 line

折月煮酒 提交于 2019-12-05 17:45:41
Let's say I have this file: 1 17:02,111 Problem report related to router 2 17:05,223 Restarting the systems 3 18:02,444 Must erase hard disk now due to compromised data I want this output: 1 17:02,111 Problem report related to router 2 17:05,223 Restarting the systems 3 18:02,444 Must erase hard disk now due to compromised data Been trying in bash and got to a kind of close solution but I don't know how to carry this out on Python. Thank you in advance If you want to remove the extea lines : For this aim you can check 2 condition for each like one if the line don't followed by an empty new

sscanf equivalent in Java [duplicate]

半城伤御伤魂 提交于 2019-12-05 14:15:24
This question already has answers here : Closed 7 years ago . Possible Duplicate: what is the Java equivalent of sscanf for parsing values from a string using a known pattern? I'm pretty new to Java, but seeing how useful the sscanf function is, I wonder if there is an equivalent in Java. I've got many pretty much formatted strings (namely, writing scripting language for my purposes), so regular expressions are overkill here. Scanner scanner = new Scanner ("2 A text 3 4"); scanner.nextInt (); // 2 scanner.next (); // A scanner.next (); // text scanner.nextInt (); // 3 scanner.nextInt (); // 4

How to remove unbalanced/unpartnered double quotes (in Java)

别等时光非礼了梦想. 提交于 2019-12-05 13:20:33
I thought to share this relatively smart problem with everyone here. I am trying to remove unbalanced/unpaired double-quotes from a string. My work is in progress, I might be close to a solution. But, I didn't get a working solution yet. I am not able to delete the unpaired/unpartnered double-quotes from the string. Example Input string1=injunct! alter ego." string2=successor "alter ego" single employer" "proceeding "citation assets" Output Should be string1=injunct! alter ego. string2=successor "alter ego" single employer proceeding "citation assets" This problem sound similar to Using Java

How can I convert a string to a float with Perl?

╄→尐↘猪︶ㄣ 提交于 2019-12-05 04:56:55
问题 Is there any function like int() which can convert a string to float value? I'm currently using the following code: $input=int(substr($line,1,index($line,",")-1)); I need to convert the string returned by substr to float. 回答1: Just use it. In Perl, a string that looks like a number IS a number. Now, if you want to be sure that the thing is a number before using it then there's a utility method in Scalar::Util that does it: use Scalar::Util qw/looks_like_number/; $input=substr($line,1,index(