string-parsing

Javascript - value exists, then disappears, then appears again?

心已入冬 提交于 2019-12-22 12:32:09
问题 This is driving me nuts. I can't work it out stepping through with Firebug either. Can someone please explain what is going on here? Basically I have an incoming text file where each line contains a pipe-delimited record. I'm splitting these into an array of array of string for later use in an autocomplete textbox. The code is as follows: <script type="text/javascript"> $(function () { var rawData = new Array(); $.get("/sample.txt", function (data) { var raw = data.split('\n'); for (var i = 0

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

假装没事ソ 提交于 2019-12-22 12:21:39
问题 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"; 回答1: 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"; 回答2: Try this: DateTime result;

How do I extract a substring from a string until the second space is encountered?

丶灬走出姿态 提交于 2019-12-20 10:25:12
问题 I have a string like this: "o1 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467" How do I extract only "o1 1232.5467" ? The number of characters to be extracted are not the same always. Hence, I want to only extract until the second space is encountered. 回答1: A straightforward approach would be the following: string[] tokens = str.Split(' '); string retVal = tokens[0] + " " + tokens[1]; 回答2: Just use String.IndexOf twice as in: string str = "My Test String"; int index = str.IndexOf

How to do simple math with a list of numbers from a file and print out the result in Rust?

让人想犯罪 __ 提交于 2019-12-20 07:47:14
问题 use std::fs::File; use std::io::prelude::*; use std::io::BufReader; use std::iter::Iterator; fn main() -> std::io::Result<()> { let file = File::open("input")?; // file is input let mut buf_reader = BufReader::new(file); let mut contents = String::new(); buf_reader.read_to_string(&mut contents)?; for i in contents.parse::<i32>() { let i = i / 2; println!("{}", i); } Ok(()) } list of numbers: 50951 69212 119076 124303 95335 65069 109778 113786 124821 103423 128775 111918 138158 141455 92800

Is there a tool for parsing a string to create a C# func?

最后都变了- 提交于 2019-12-20 02:27:08
问题 I need to know if there is any library out there that will allow me to, given a certain string representing a mathematical function, say, x^2+x+1 , (don't care about how the string format, any will work for me) generates a C# func that will represent said function. 回答1: Been using FLEE (Fast Lightweight Expression Evaluator) for a while now and it's been working great. They have a version that maintains most functionality for Silverlight as well. It's designed to do pretty much exactly what

In F#, is it possible to have a tryParse function that infers the target type

假装没事ソ 提交于 2019-12-19 03:17:07
问题 Presently we do this... let parseDate defaultVal text = match DateTime.TryParse s with | true, d -> d | _ -> defaultVal Is it possible to do this... let d : DateTime = tryParse DateTime.MinValue "2015.05.01" 回答1: Yes. Welcome to the world of member constraints, ref, and byref values. let inline tryParseWithDefault defaultVal text : ^a when ^a : (static member TryParse : string * ^a byref -> bool) = let r = ref defaultVal if (^a : (static member TryParse: string * ^a byref -> bool) (text, &r

In F#, is it possible to have a tryParse function that infers the target type

落花浮王杯 提交于 2019-12-19 03:16:13
问题 Presently we do this... let parseDate defaultVal text = match DateTime.TryParse s with | true, d -> d | _ -> defaultVal Is it possible to do this... let d : DateTime = tryParse DateTime.MinValue "2015.05.01" 回答1: Yes. Welcome to the world of member constraints, ref, and byref values. let inline tryParseWithDefault defaultVal text : ^a when ^a : (static member TryParse : string * ^a byref -> bool) = let r = ref defaultVal if (^a : (static member TryParse: string * ^a byref -> bool) (text, &r

Counting the number of occurences of characters in a string [duplicate]

自作多情 提交于 2019-12-18 07:24:45
问题 This question already has answers here : Java compressing Strings (19 answers) Closed 5 years ago . I am trying to write a Java program which takes in as input a string and counts the number of occurrences of characters in a string and then prints a new string having the character followed by the no of occurrences. E.G. Input String: aaaabb Output String: a4b2 Input String: aaaaabbbc Output String: a5b3c1 I am posting my java code. It is throwing StringOutOfBoundException /*Write a routine

Regular Expressions - Matching IRC-like parameters?

人盡茶涼 提交于 2019-12-18 04:23:16
问题 I am looking to create a IRC-like command format: /commandname parameter1 "parameter 2" "parameter \"3\"" parameter"4 parameter\"5 Which would (ideally) give me a list of parameters: parameter1 parameter 2 parameter "3" parameter"4 parameter\"5 Now from what I have read, this isn't at all trivial and might as well be done in some other method. Thoughts? Below is C# code that does the job I need: public List<string> ParseIrcCommand(string command) { command = command.Trim(); command = command

Get number of characters read by sscanf?

北城余情 提交于 2019-12-17 10:56:19
问题 I'm parsing a string (a char* ) and I'm using sscanf to parse numbers from the string into doubles, like so: // char* expression; double value = 0; sscanf(expression, "%lf", &value); This works great, but I would then like to continue parsing the string through conventional means. I need to know how many characters have been parsed by sscanf so that I may resume my manual parsing from the new offset. Obviously, the easiest way would be to somehow calculate the number of characters that sscanf