Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a problem with Substring function. As you can see on Watch window shcreenshot I have the variable called val equal to 03.09.2015 17:30
I do not understand why but
val.Substring(0,2) returns 0 instead of 03
val.Substring(0,3) returns 03 (string of two symbols)
What am I doing wrong?
Your string contains non-printable characters. Note the following from your screenshot:
val = "03.09.2015 17:30"
val.Length = 21
However, 03.09.2015 17:30 only has 16 characters. Thus, the string contains other, zero-width characters.
To find the culprit, output a hex dump of your problematic string and compare it with the hex dump of the literal string 03.09.2015 17:30.
From OP comment:
The original problem was with Parse (and Parse-like) functions. It can not parse this string as Date or DateTime
Once the invisible characters are removed from the string, it certainly can be parsed:
Dim d As Date = DateTime.Parse("03.09.2015 17:30", Globalization.CultureInfo.InvariantCulture)
Dim m As Integer = d.Month ' m = 3
Of course, choose the particular Parse method that best fits your needs.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a dataframe which looks as following:
df['col1'].values
array(['cat 113kd29', 'do56goat24kdasd', 'pig145kd'])
I need to create a new column df['vals'] with following values:
cat 29
do56goatasd
pig
i.e. first I need to look for substring kd and then find the numeric value preceding it. I am not sure how to go about this.
There can be multiple numeric values in each string so I need to find only ones before kd. Please note the string 'cat 113kd29'. Also look at 'do56goat24kdasd'
I tried the following but it didn't work:
df['col1'].str.replace(r'(\d+)kd', '')
Your call to str.replace is correct, but you need to assign it to the original Pandas column on the left hand side of an assignment:
df["col1"] = df["col1"].str.replace(r'\d+kd', '')
Note that str.replace does a global replacement by default, so there is no need to use any sort of flag.
Another way is to match digits precedingkd and kd and replace it with nothing
df["col1"]=df.col1.str.replace('\d+kd\Z','', regex=True)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Trying to convert a number string into an INT64 in VB.NET. The number I am testing with is 12804494279291877304.
The error I am getting is "Value was either too large or too small for an Int64."
Code sample below.
BigInt = CLng(EncodeNumber)
It's too big, doesn't fix in a INT64. It would fit in a UINT64.
Dim v As UInt64
v = UInt64.Parse("12804494279291877304")
Like #Çöđěxěŕ said, using TryParse allow the use of proper error handling.
If Not UInt64.TryParse("12804494279291877304", v) Then
' Handle wrong input
End If
Your number is too big for Int64, so you could use BigInteger, please see https://learn.microsoft.com/en-us/dotnet/api/system.numerics.biginteger?view=netframework-4.8
You can use unsigned Int64 as others suggest but beware that it won't hold negative numbers and also has a limit of 18446744073709551615
I am working on some legacy code at the moment and have come across the following:
FooString = String.Format("{0:####0.000000}", FooDouble)
My question is, is the format string here, ####0.000000 any different from simply 0.000000?
I'm trying to generalize the return type of the function that sets FooDouble and so checking to make sure I don't break existing functionality hence trying to work out what the # add to it here.
I've run a couple tests in a toy program and couldn't see how the result was any different but maybe there's something I'm missing?
From MSDN
The "#" custom format specifier serves as a digit-placeholder symbol.
If the value that is being formatted has a digit in the position where
the "#" symbol appears in the format string, that digit is copied to
the result string. Otherwise, nothing is stored in that position in
the result string.
Note that this specifier never displays a zero that
is not a significant digit, even if zero is the only digit in the
string. It will display zero only if it is a significant digit in the
number that is being displayed.
Because you use one 0 before decimal separator 0.0 - both formats should return same result.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a form with a textbox. In the textbox the user will insert a youtube link such as: 'https://www.youtube.com/watch?v=IJNR2EpS0jw' . However I only need this part of the URL 'youtube.com/watch?v=IJNR2EpS0jw' . So my question is how can I write a code to store the selected part of the URL I need. I think it needs to start of like this:
Dim specificurl As String
specificurl = TextBox1.Text.StartsWith("youtube.com")
Regards
You can use the String.Replace method to strip the https://www. out of the string.
Dim URLString As String = "http://www.youtube.com/watch?v=..."
URLString = URLString.Replace("https://www.", "")
URLString = URLString.Replace("http://www.", "")
This will get you the value you're looking for.
If there's any chance your input may have capital letters (unlikely since this is a URL), you'd need to use Regex to do the replacement (this would also let you do both HTTP and HTTPS in one line):
Dim newValue As String = Regex.Replace(input, "^https*://", String.Empty,
RegexOptions.IgnoreCase)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Remove a random expression from string
I have a column which contains values like this
"000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF";
I want to create a substring which doesn't have the part x3A 973911 in it.
Whic means I want something like this,
000003023_AggregateStopLossLimit_W_2012-12-22.PDF
The value x3A 973911 is not constant, so basically, in words, I want the part of string to be removed which comes after the first space and ends at the next '_'.
Any ideas ?
String phrase="000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF";
phrase.replace("x3A 973911","");
//am not sure if you have to trim() but i guess this will answer your question.