Related
I'm building a string in oracle, where I get a number from a column and make it a 12 digit number with the LPad function, so the length of it is 12 now.
Example: LPad(nProjectNr,12,'0') and I get 000123856812 (for example).
Now I want to split this string in parts of 3 digit with a "\" as prefix, so that the result will look like this \000\123\856\812.
How can I archive this in a select statement, what function can accomplish this?
Assuming strings of 12 digits, regexp_replace could be a way:
select regexp_replace('000123856812', '(.{3})', '\\\1') from dual
The regexp matches sequences of 3 characters and adds a \ as a prefix
It is much easier to do this using TO_CHAR(number) with the proper format model. Suppose we use \ as the thousands separator.... (alas we can't start a format model with a thousands separator - not allowed in TO_CHAR - so we still need to concatenate a \ to the left):
See also edit below
select 123856812 as n,
'\' || to_char(123856812, 'FM000G000G000G000', 'nls_numeric_characters=.\') as str
from dual
;
N STR
--------- ----------------
123856812 \000\123\856\812
Without the FM format model modifier, TO_CHAR will add a leading space (placeholder for the sign, plus or minus). FM means "shortest possible string representation consistent with the model provided" - that is, in this case, no leading space.
Edit - it just crossed my mind that we can exploit TO_CHAR() even further and not need to concatenate the first \. The thousands separator, G, may not be the first character of the string, but the currency symbol, placeholder L, can!
select 123856812 as n,
to_char(123856812, 'FML000G000G000G000',
'nls_numeric_characters=.\, nls_currency=\') as str
from dual
;
SUBSTR returns a substring of a string passed as the first argument. You can specify where the substring starts and how many characters it should be.
Try
SELECT '\'||SUBSTR('000123856812', 1,3)||'\'||SUBSTR('000123856812', 4,3)||'\'||SUBSTR('000123856812', 7,3)||'\'||SUBSTR('000123856812', 10,3) FROM dual;
Could somebody help me to extract the string between dash (-) and dot (.) at the last of URL in ASP classic?
For example:
mypizza.com/this-is-my-special-6-pizza-this-week-3256.html
How can I extract the 3256 value?
PS: There are many dashes and some numbers appear in URL.
This works if you definitely have a dash before the number. If you could have a / before the number then add another replace for / into -.
dim s, aSplit
s = "mypizza.com/this-is-my-special-6-pizza-this-week-3256.html"
s = replace(s, ".", "-") ' replace any dots with dashes
aSplit = split(s, "-") ' break s into an array, splitting at dashes. Note it is a zero-based array.
dim sOut
sOut = aSplit(ubound(aSplit) - 1) ' get the penultimate entry in the array
Solved!
I found the answer:
Dim n, strPost
dashCount = len(urlPost)-len(replace(urlPost,"-",""))
n=dashCount
thisURL=split(urlPost,"-")
strPost=replace(thisURL(n),".html","")
response.write(strPost)
I have a file with the following inputs
"SMEGOLD 1312",20131127,"C","11606233E","SMX","C",20131009,170028,"SMX","70207",0,1,4699,0,469.9,"USD",0,"",0,"",0,"",0,"",0,0,0,8062696,"",0,20131009,170028,"SYSTEM","25228","","166","121328200000223",785,0,"","","","","","","","","","","","",0,0,0,"",20131009,170028,"ADVMEE"
"SMEGOLD 1312",20131127,"C","11606233E","SMX","C",20131009,170030,"SMX","70207",0,1,4699,0,469.9,"USD",0,"",0,"",0,"",0,"",0,0,0,8062697,"",0,20131009,170031,"SYSTEM","25228","","167","121328200000223",786,0,"","","","","","","","","","","","",0,0,0,"",20131009,170028,"ADVMEE"
What i would like to achieve is to only obtain the first quote text of the line. Example "SMEGOLD 1312". Then i would like to append the first 3 characters and the last 4 characters of that extracted text to the back of line.
And move to the next line to carry on with the procedure till the end of the file.
Any advise will be a great help. I tried using the objRegEx.Pattern but to no avail
Thanks
Use a pattern that cuts/groups the first field in toto (1), its first three (2) and its last four (3) characters, and all the rest (4). Then .Replace creatively:
>> s = Replace("'SMEGOLD 1312','whatever','ADVMEE'", "'", """")
>> WScript.Echo s
>> Set r = New RegExp
>> r.Pattern = "^((""[^""]{3})[^""]*?([^""]{4}""))(.*)"
>> WScript.Echo r.Replace(s,"$1$4,$2$3")
>>
"SMEGOLD 1312","whatever","ADVMEE"
"SMEGOLD 1312","whatever","ADVMEE","SME1312"
I have 6400+ records which I am looping through. For each of these: I check that the address is valid by testing it against something similar to what the Post Office uses (find address). I need to double check that the postcode I have pulled back matches.
The only problem is that the postcode may have been inputted in a number of different formats for example:
OP6 6YH
OP66YH
OP6 6YH.
If Replace(strPostcode," ","") = Replace(xmlAddress.selectSingleNode("//postcode").text," ","") Then
I want to remove all spaces from the string. If I do the Replace above, it removes the space for the first example but leave one for the third.
I know that I can remove these using a loop statement, but believe this will make the script run really slow as it will have to loop through 6400+ records to remove the spaces.
Is there another way?
I didn't realise you had to add -1 to remove all spaces
Replace(strPostcode," ","",1,-1)
Personally I've just done a loop like this:
Dim sLast
Do
sLast = strPostcode
strPostcode = Replace(strPostcode, " ", "")
If sLast = strPostcode Then Exit Do
Loop
However you may want to use a regular expression replace instead:
Dim re : Set re = New RegExp
re.Global = True
re.Pattern = " +" ' Match one or more spaces
WScript.Echo re.Replace("OP6 6YH.", "")
WScript.Echo re.Replace("OP6 6YH.", "")
WScript.Echo re.Replace("O P 6 6 Y H.", "")
Set re = Nothing
The output of the latter is:
D:\Development>cscript replace.vbs
OP66YH.
OP66YH.
OP66YH.
D:\Development>
This is the syntax Replace(expression, find, replacewith[, start[, count[, compare]]])
it will default to -1 for count and 1 for start. May be some dll is corrupt changing the defaults of Replace function.
String.Join("", YourString.Split({" "}, StringSplitOptions.RemoveEmptyEntries))
Because you get all strings without spaces and you join them with separator "".
Hey all, i am trying to replace large spaces between text with just one. My output looks like this right now:
5964215">
This is just the first example of the spaces
5964478">
This would be the 2nd example of showing how many spaces this thing has in each sentence.
5964494">
That comes from a textbox that has multi-line to true. Here is what it looks like when it doesn't have multi-line to true.
http://www.june3rdsoftware.com/forums/vb6.jpg
I can not seem to get the spaces to go away! BTW, this text is from a webpage if that makes any difference.
David
According to the suggestion of MvanGeest, here is some VB code to replace blocks of white spaces:
Sub test()
Dim x As String, y As String
x = "abcd defg 1233"
Dim re As New RegExp
re.Pattern = "\s+"
re.Global = True
y = re.Replace(x, " ")
Debug.Print y
End Sub
To make this work, you will have to add a reference to "Microsoft VBScript Regular Expresssions" to your project.
Assuming no regex support, why not set up a simple state machine that will set the state=1 when a space is found and set state=0 once a non-space is encountered. You can move char by char when state=0 (thus copying over only 1 space per series of spaces).
Also assuming no regex, you could try something like
str = "long text with spaces "
i = LenB(str)
str = Replace(str, " ", " ")
Do While LenB(str) <> i
i = LenB(str)
str = Replace(str, " ", " ")
Loop
Of course this code could be optimized for long space sequences but it might be all you need as well