Stated below is a string from which I want to remove the ' and want to pass the formatted string in the PLSQL parameter. Can anyone help me out in this?
The string is:
'BKGSSS220005823','BKGSSS220005824','BKGSSS220005786','BKGSSS220005756','BKGSSS220005858','BKGSSS220005843','BKGSSS220005845','BKGSSS220005862','BKGSSS220005777','BKGSSS220005861','BKGSSS220005867','BKGSSS220005825','BKGSSS220005863','BKGSSS220005859','BKGSSS220005878','BKGSSS220005755','BKGSSS220005877','BKGSSS220005827','BKGSSS220005879','BKGSSS220005852','BKGSSS220005831'
This should do it, don't understand why this was hard.
Dim someString As String
someString = "'BKGSSS220005823','BKGSSS220005824','BKGSSS220005786','BKGSSS220005756','BKGSSS220005858','BKGSSS220005843','BKGSSS220005845','BKGSSS220005862','BKGSSS220005777','BKGSSS220005861','BKGSSS220005867','BKGSSS220005825','BKGSSS220005863','BKGSSS220005859','BKGSSS220005878','BKGSSS220005755','BKGSSS220005877','BKGSSS220005827','BKGSSS220005879','BKGSSS220005852','BKGSSS220005831'"
someString = someString.Replace("','", ",")
Dim sampleString As String = "'BKGSSS220005823','BKGSSS220005824','BKGSSS220005786','BKGSSS220005756','BKGSSS220005858','BKGSSS220005843','BKGSSS220005845','BKGSSS220005862','BKGSSS220005777','BKGSSS220005861','BKGSSS220005867','BKGSSS220005825','BKGSSS220005863','BKGSSS220005859','BKGSSS220005878','BKGSSS220005755','BKGSSS220005877','BKGSSS220005827','BKGSSS220005879','BKGSSS220005852','BKGSSS220005831'"
Console.WriteLine("'" & sampleString.Replace("'","") & "'")
Try it here .Net Fiddle
Related
I have a string which needs converting to "dd/MM/yy". I am converting it to a Date datatype and then formatting it back to a string. I was wondering if there is an easier/elegant way of doing it.
Here is an example of how I am achieving this now
Dim strValue As String = "17/08/2016"
Dim dteValue as Date = Convert.ToDateTime(strValue)
strValue = dteValue.ToString("dd/MM/yy")
What I am looking for is a way of converting without casting it to a Date datatype, is it possible?
Without casting it to Date I would suggest:
Dim strValue As String = "17/08/2016"
strValue = strValue.PadLeft(6) & strValue.PadRight(2)
It takes my computer 1 ms to process above code 10.000 times, but 22 ms to process yours.
Edit: if the date has different lengths, you could split on the forwardslash and rebuilt it:
Dim arrSplitValue() As String = Split("17/08/2016", "/")
Dim strValue As String = arrSplitValue(0) & "/" & arrSplitValue(1) & "/" & arrSplitValue(2).PadRight(2)
You could use an extension method:
public static string ToMyDateString(this string stringDate)
{
return DateTime.Parse(stringDate).ToString("dd/MM/yy");
}
And then use it like so:
string strValue = "17/08/2016".ToMyDateString();
or
string strValue = "17/08/2016";
string strValueDate = strValue.ToMyDateString();
Just realised you're in VB.NET so pretty sure it'll translate over. If I get a moment I'll try and do it in VB.NET.
VB.NET version
<System.Runtime.CompilerServices.Extension> _
Public Shared Function ToMyDateString(stringDate As String) As String
Return DateTime.Parse(stringDate).ToString("dd/MM/yy")
End Function
Warning - this has just been put through a converter, so may need to be tweaked.
How do I search in a string from ";" to ";"?
Dim strInput as String = "text1;text2;text3"
Solution should look like this:
strOutput1 = "text1"
strOutput2 = "text2"
strOutput3 = "text3"
The lenght of the single "parts" is not fix, strInput can also be like "12345;name;Christoph;"
I just want to get the parts in a own string.
Does anybody knows how to?
Quickest way is probably using SPLIT to populate an array then set the individual variables to each element in the array. The only issue that might arise is if you have ;'s inside the strings, but that would pretty much prevent anything not based on length.
Starting with your string:
Dim strInput as String = "text1;text2;text3"
Then do a split:
Dim inputArray() As String = Split(strInput, ";")
This will split your string up using ; as the delineator. So you will end up with this:
inputArray(0) = "text1"
inputArray(1) = "text2"
inputArray(2) = "text3"
More on split()...
https://msdn.microsoft.com/en-us/library/6x627e5f%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396
Using .Split you can separate the original string into an array of strings like this
Dim strInput As String = "text1;text2;text3"
Dim tempStringList() As String = strInput.Split(";"c)
So now
tempStringList(0) contains "text1"
tempStringList(1) contains "text2"
and so on.
The beauty of .split is that it doesnt care how many sections there are to separate.
I have a string xxx1-0.1/1 yyy,ccc1,1. I used split and substring. All i want to get is the 0.1/1 only. Is there any optimize way to do this?
Thank you in advance!
Use more than one string split chars. then if the position and format is always the same then this will work.
Dim s As String = "xxx1-0.1/1 yyy,ccc1,1"
Dim ans = s.Split(New Char() {"-"c, " "c})(1)
MessageBox.Show(ans)
Lets make it a function:
Private Function getMySpecialValue(input As String) As String
Return input.Split(New Char() {"-"c, " "c})(1)
End Function
I have to following string:
Dim text As String = "userĖ˛upload"
I want to change the Unicode character #0332 to underscore. I have the following code for this:
Dim test As New Text.StringBuilder
test.Append(text.Replace("#0332", "_"))
Dim normalizedUrl As String = test.ToString()
However it does not work, my "test" string has the same value as "text" variable. Anyone has an idea what can be wrong?
You can;
text.Replace(ChrW(&H332), "_")
say if I have a string 010451-09F2
How to I get left of - from the above string in vb.net
I want 010451
The left function doesn't allow me to specify seperator character.
Thanks
Given:
Dim strOrig = "010451-09F2"
You can do any of the following:
Dim leftString = strOrig.Substring(0, strOrig.IndexOf("-"))
Or:
Dim leftString = strOrig.Split("-"c)(0) ' Take the first index in the array
Or:
Dim leftString = Left(strOrig, InStr(strOrig, "-"))
' Could also be: Mid(strOrig, 0, InStr(strOrig, "-"))
Dim str As String = "010451-09F2"
Dim leftPart As String = str.Split("-")(0)
Split gives you the left and right parts in a string array. Accessing the first element (index 0) gives you the left part.
Sorry not sure on the vb syntax, but the c# is
string mystring ="010451-09F2";
string whatIwant = mystring.Split('-')[0];
Get the location of the dash first (or do it inline), and use that value for the left. This is old school VBA, but it'll be something like this:
Left(YourStringWithTheDash, InStr(YourStringWithTheDash)-1)
dim s as String = "010451-09F2"
Console.WriteLine(s.Substring(0, s.IndexOf("-")))
Console.WriteLine(s.Split("-")(0))
Use something like this:
Mid("010451-09F2",1,InStr("-"))
Dim sValue As String = "010451-09F2"
Debug.WriteLine(sValue.Substring(0, sValue.IndexOf("-"c)))
This helped
Dim str1 as string = me#test.com
Dim str As String
str = Strings.Left(str1, str1.LastIndexOf("#"))