numbers

Get multiple numbers from a string

允我心安 提交于 2019-12-01 12:03:13
I have strings like AS_!SD 2453iur ks@d9304-52kasd I need to get the 2 frist numbres of the string: for that case will be: 2453 and 9304 I don't have any delimiter in the string to try a split, and the length of the numbers and string is variable, I'm working in C# framework 4.0 in a WPF. thanks for the help, and sorry for my bad english This solution will take two first numbers, each can have any number of digits string s = "AS_!SD 2453iur ks@d9304-52kasd"; MatchCollection matches = Regex.Matches(s, @"\d+"); string[] result = matches.Cast<Match>() .Take(2) .Select(match => match.Value)

a simple function for return number from string in php

Deadly 提交于 2019-12-01 11:32:27
I want capture Rank from this code : $RankStr = 'var trafficstatsSnippet = "/site/trafficstats;pysa1bpbPOVl6Wm5d4Zv4nKXKdM%3D /aahoonet.com/?adult=&category=&rank=1234567";' I use this code : $NewPOS = strpos($RankStr, "rank="); $SRank = substr($RankStr, $NewPOS + 5, 10); echo $SRank; because of RANK code variable from (1 - 25,000,000) , i use above code by selecting maximum 10 charachters after starting position of rank= plus 5 further index. so this function return 1234567"; and after that i want to grab this number from string. trying preg_match_all or regex but becasue of nofamiliarity

Numbers not formatted properly in Struts 2

≡放荡痞女 提交于 2019-12-01 11:07:39
问题 I am using following syntax to display a value in a proper number format, e.g. 1,250.00 . <s:property value="%{getText('{0,number,#,##0.00}',#plan.amount)}" /> However, it is not working. The plan is an object with a property amount. 回答1: If the value is printed like 1250.00 then it's not formatted properly. The method getText() has many overloaded methods and which method is used is determined by the parameter's types and count. To pass arguments to the getText() method you can use OGNL list

C# - Excel Number Formatting Issue with International settings

瘦欲@ 提交于 2019-12-01 11:01:50
I am trying to write to an Excel 2003 spreadsheet using c# 3.5. However I am unable to get this to function correctly across different country settings. The country settings are either English or German. These two settings have different decimal and thousands settings. Everything works fine unless a user has changed the decimal and thousands separators in the International settings of the Options screen. Can anybody help as I feel I can no longer see the wood for the trees and am missing something obvious. Summary: Data retrieved from an access database. Read by c# application and written to

How to make TextBox to receive only number key values using KeyDown Event in C#?

守給你的承諾、 提交于 2019-12-01 10:56:33
问题 This code in my form updates the textBox1.Text twice whenever number keys are pressed. private void textBox1_KeyDown( object sender, KeyEventArgs e ) { //MessageBox.Show(); if( char.IsNumber((char)e.KeyCode) ) { textBox1.Text += (char)e.KeyCode; } } Explain why if you can? Modify the code or provide me a better solution for this. Input ( in textbox1 ): 54321 Output: 1234554321 回答1: When you press a key, a character is already appended to your TextBox . Then you run the following code and, if

C# Extension Method for String Data Type

Deadly 提交于 2019-12-01 10:56:14
My web application deals with strings that need to be converted to numbers a lot - users often put commas, units (like cm, m, g, kg) and currency symbols in these fields so what I want to do is create a string extension method that cleans the field up and converts it to a decimal. For example: decimal myNumber = "15 cm".ToDecimal(); Are you expecting users of different 'cultures' to use your application? If so it's better to factor in the user's regional settings: static decimal ToDecimal(this string str) { return Decimal.Parse(str, CultureInfo.CurrentCulture); } Or you could replace every

Getting the number of days between two dates in java [duplicate]

本小妞迷上赌 提交于 2019-12-01 10:55:30
问题 This question already has answers here : Calculating the difference between two Java date instances (45 answers) Calculate date/time difference in java [duplicate] (17 answers) Closed 6 years ago . Hi have two dates in date format, how do i get the difference of days between the two ? Date date1; Date date2 ; int numberDays = ? 回答1: The recommendation is to use JodaTime API for Dates: import java.util.logging.Logger; import org.joda.time.DateTime; import org.joda.time.Duration; import org

Add a new column with tag attached to crescent numbers

我的未来我决定 提交于 2019-12-01 10:05:14
问题 I would like to add a new collumn giving a constant tag with anexed with a crescent numbers logic, line after line. My input: position work chr1 jil2001 chr4 jil2001 chr3 kou2009 chr9 nai2012 chr7 fandis2005 My expected output: position work tag chr1 jil2001 Known1 chr4 jil2001 Known2 chr3 kou2009 Known3 chr9 nai2012 Known4 chr7 fan2005 Known5 Cheers! 回答1: You can create the new column manually; df$tag <- paste0("Known", seq_len(nrow(df))) 来源: https://stackoverflow.com/questions/22883998/add

How to divide large numbers and what algorithm to use

╄→гoц情女王★ 提交于 2019-12-01 09:41:52
I want to manipulate really big numbers and I am trying to work with arrays. I have already implemented the multiplication operation, but now I want to implement the division operation. I was wondering which algorithm(s) should I use? Is it possible to use the Newton–Raphson division algorithm or maybe should I use the algorithm that we learned in the school? PS: I know that there are many libraries that work with big numbers, but I want to do this for practice. Spektre These are my favorite algorithms I use: Binary division Look here: http://courses.cs.vt.edu/~cs1104/BuildingBlocks/divide.030

What is the most efficient way to find amicable numbers in python?

梦想的初衷 提交于 2019-12-01 08:28:46
I've written code in Python to calculate sum of amicable numbers below 10000: def amicable(a, b): total = 0 result = 0 for i in range(1, a): if a % i == 0: total += i for j in range(1, b): if b % j == 0: result += j if total == b and result == a: return True return False sum_of_amicables = 0 for m in range (1, 10001): for n in range (1, 10001): if amicable(m, n) == True and m != n: sum_of_amicables = sum_of_amicables + m + n Code is running more than 20 minutes in Python 2.7.11. Is it ok? How can I improve it? optimized to O(n) def sum_factors(n): result = [] for i in xrange(1, int(n**0.5) + 1