Find one character in a string and count the amount of times its found
Hey SQL Forum experts.
I have a string that is about 3000 characters long.
I'm trying to search my string for the value '{'.
Then I want to count how many times this value is found.
How do I form the Oracle SQL to do this?
Hi Colin,
Try the following:
SQL> var s varchar2(100)
SQL>
SQL> exec :s := 'Colin {{ Mackenzie {{{'
PL/SQL procedure successfully completed.
SQL> select length(:s) - length(replace(:s, '{')) Matches from dual;
MATCHES
5
SQL> exec :s := 'I have a string that is about 3000 characters long'
PL/SQL procedure successfully completed.
SQL> select length(:s) - length(replace(:s, '{')) Matches from dual;
MATCHES
0Regards.
Similar Messages
-
Hello,
I am doing a project that uses MS Access to access data about a baseball team . The MS Access Database provides the names, addresses, and age of the players. All the players are 12, 13, or 14 years old. I need to display the average age for the team on a
label, which was easy. The problem is that I also have to display the number of players who are 12, 13, and 14 years old and I have no idea how to do that.
Here is my code so far:
Public Class frmBaseball
Private Sub TeamBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TeamBindingNavigatorSaveItem.Click
Me.Validate()
Me.TeamBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.LittleLeagueDataSet)
End Sub
Private Sub frmBaseball_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LittleLeagueDataSet.Team' table. You can move, or remove it, as needed.
Me.TeamTableAdapter.Fill(Me.LittleLeagueDataSet.Team)
End Sub
Private Sub btnAges_Click(sender As Object, e As EventArgs) Handles btnAges.Click
Dim strSql As String = "SELECT * FROM Team"
Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" & "Data Source=e:\LittleLeague.accdb"
Dim odaTeam As New OleDb.OleDbDataAdapter(strSql, strPath)
Dim datAge As New DataTable
Dim intCount As Integer = 0
Dim intTotalAge As Integer
Dim decAverageAge As Decimal
odaTeam.Fill(datAge)
odaTeam.Dispose()
For intCount = 0 To datAge.Rows.Count - 1
intTotalAge += Convert.ToInt32(datAge.Rows(intCount)("Age"))
decAverageAge = Convert.ToDecimal(intTotalAge / datAge.Rows.Count)
Next
lblAverage.Visible = True
lblAverage.Text = "The average age of the team is " & decAverageAge.ToString("N2")
lbl12.Text = "The number of 12 year olds is "
lbl13.Text = "The number of 13 year olds is "
lbl14.Text = "The number of 14 year olds is "
lbl12.Visible = True
lbl13.Visible = True
lbl14.Visible = True
End Sub
End Class
I think I should use a For..Next loop but I don't know how to identify and match using this database, and then count how many repeated 12, 13, 14 years old there are.
Any help would be really appreciated.Hello,
Conceptually speaking you would group the data and count. Beings this is school work the demo below is a static example and not suitable for your assignment, its to show a point. Now if you have learned about LINQ and Lambda this logic can apply to your
question but need to work out using this your data which can be done. If not look at using SQL Grouping.
Example of SQL grouping and count
select country, count(country) as count from customers group by country
Module Module1
Public Sub GroupingDemo()
Dim dt As DataTable = SimulateLoadFromDatabase()
Dim TeamData = dt.AsEnumerable.GroupBy(
Function(student) student.Field(Of Integer)("Age")) _
.Select(Function(group) New With
Key .Value = group.Key,
Key .Info = group.OrderByDescending(
Function(x) x.Field(Of String)("Name"))}) _
.OrderBy(
Function(group) group.Info.First.Field(Of Integer)("age"))
Dim dictData As New Dictionary(Of String, String)
For Each group In TeamData
Console.WriteLine("Group: {0} count: {1} ", group.Value, group.Info.Count)
dictData.Add(group.Value.ToString, group.Info.Count.ToString)
' The following is not needed but good to show
For Each item In group.Info
Console.WriteLine(" {0} {1}",
item.Field(Of Integer)("Identifier"),
item.Field(Of String)("Name"))
Next
Next group
Console.WriteLine()
Console.WriteLine("This data can be used to populate control text")
For Each Item As KeyValuePair(Of String, String) In dictData
Console.WriteLine("{0} {1}", Item.Key, Item.Value)
Next
End Sub
Private Function SimulateLoadFromDatabase() As DataTable
Dim dt As New DataTable With {.TableName = "MyTable"}
dt.Columns.Add(New DataColumn With {.ColumnName = "Identifier", .DataType = GetType(Int32),
.AutoIncrement = True, .AutoIncrementSeed = 1})
dt.Columns.Add(New DataColumn With {.ColumnName = "Name", .DataType = GetType(String)})
dt.Columns.Add(New DataColumn With {.ColumnName = "Age", .DataType = GetType(Int32)})
dt.Rows.Add(New Object() {Nothing, "Bill", 13})
dt.Rows.Add(New Object() {Nothing, "Karen", 14})
dt.Rows.Add(New Object() {Nothing, "Jim", 13})
dt.Rows.Add(New Object() {Nothing, "Paul", 15})
dt.Rows.Add(New Object() {Nothing, "Mike", 14})
dt.Rows.Add(New Object() {Nothing, "Jill", 13})
Return dt
End Function
End Module
Output in the IDE output window
Group: 13 count: 3
3 Jim
6 Jill
1 Bill
Group: 14 count: 2
5 Mike
2 Karen
Group: 15 count: 1
4 Paul
This data can be used to populate control text
13 3
14 2
15 1
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. -
How do you count the amount of times a button is clicked?
Heres my code:
public void buttonClicked(JButton buttonzilla){
if(buttonzilla == startButton){
while(i < 7){
story.append("\n" + "\n" + abc);
i++;
However, when i click the button once, it displays all elements in the array, however, im trying to get it so that each time i click the button another element is displayed, one at a time. How would i go about doing this?Can you explain the code because it dosent make sense
to me, im a beginner.In the code you posted, there is no declaration for the variable i, so I've assumed it is declared as a class variable, and has scope within the class.
You say you want to add only the data from the element of abc[], relative to the number of times the button has been clicked i.e. 1st click adds abc[0], 2nd click adds abc[1] etc.
if(i < abc.length) - to ensure no ArrayIndexOutOfBoundsException (really should also check i is not negative)
story.append("\n" + "\n" + abc[i++]);
instead of
story.append("\n" + "\n" + abc);
i++; -
Count the number of times a character is in a string using pl/sql
I need to count the number of times ":" appers in the string ":XXX:CCC:BBB:".
I have sound some solution using SQL but I do not want the context switch.
Also I am on 10g so I can not use REGEXP_COUNT.
Any help would be great.Hi,
length(REGEXP_REPLACE(':XXX:CCC:BBB:','[[:alnum:]]'))counts all kinds of punctuation, spaces, etc., not just colons. Change any (or all) of the colons to periods and it will still return 4. Use '[^:]' instead of '[[:alnum:]]' if you really want to count just colons.
Also, "SELECT ... FROM dual" is usually needed only in SQL*Plus or similar front end tools. In PL/SQL, you can call functions without a query, like this:
x := NVL (LENGTH (REGEXP_REPLACE (txt, '[^:]')), 0); -
Program to count the no. of times a character occurs in a string.
program to count the no. of times a character occurs in a string.
Say if u have a method :- Countclass(string s,char c) then using this u should be able to count a char ' T' in the string ="TESTING".
So it is appering 2 times.
How to count it.int countChar(String s, char c) {
int count = 0;
for (int i=0; i<s.length(); i++) {
if (s.charAt(i) == c)
count++;
return count;
} -
I was in full screen mode and now that I have exited, the main toolbar for Safari is gone. So please don't say go to View. Each time I click off of safari to the desktop, it shows me the Finder Toolbar. I have opened and closed Safari many many times.
No no, if you read what I said, it would be that each individual display would be customizable to the user. The way you have it, it sounds like your second display will be dedicated to scrolling through fullscreen apps not allowing you to do it on the home screen. This is silly because with my concept, you could do that, by dragging apps to fullscreen in your second display, but if you want you could tell another display to scroll through fullscreen apps (independently) if you wanted. Each display will have it's own mission control with it's own set of desktops. I also can see how some people would still want them linked together, so this could just be a little check box made in mission control prefs to "link" or "unlink" desktops with link checked by default.
With your solution you're limited to your setup. but what if the person has three or four displays? Well then your solution would limit them to one dedicated display that scrolls through fullscreen apps where mine lets a person customize their desktops depending on their preference and setup.
further example: if you have safari, address book and mail in one display, you could still have ichat, PS and Illustrator in your second, and a text editor, FTP Client and iTunes in your third. Then you would mix and match these apps but it would promote the use of mulitple displays as well as benefit people with three or more, which thunderbolt, Cinema Display and Pro computers support. -
Jasper report on HTML when one image loaded from database and for the other
How to generate jasper report on HTML when one image loaded from database and for the other we give a image path
My code
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, strImageInputDirectory);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME, strImageOutputPath == null ? "." : strImageOutputPath);
exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporter.exportReport();
byte[] bdata = ((ByteArrayOutputStream) baos).toByteArray();
Can any one help pls
Message was edited by:
ameet.auhey sorry for posting it in this forum.
but do u have sample code for making it work.. since i am able to do it on PDF format(image from Database and another stored in the webserver) using
byte image[] =(byte[]) outData.get("image");
ByteArrayInputStream img = new ByteArrayInputStream(image);
hmimg.put("P_PARAMV3", img);
print = JasperFillManager.fillReport(reportFileName, hmimg, jrxmlds);
bdata= JasperExportManager.exportReportToPdf(print); -
I recently bought a new i phone 4 as my other one had seen beter days and for the last sevral days have been trying to transfer my photos ect from my old phone to my new one after I've plugged my old iPhone into iTunes to back it up i then plug in my one to transfer it over I've had no luck I've tryed restoring my new phone to the last time i backed up my old files the phone restores but always to its own backup point wen i first connected it to iTunes can anyone help me please?
Since this is the second computer you've had this problem with, I recommend you look for answers on the iPhone forum. My thinking is it is an iPhone issue rather than a computer issue (unless it is some software incompatibility).
-
Hi when I stream video content to my Tv using Apple tv from my Ipad3 I find the Ipad goes to sleep after 2/3 minutes and disconects, the only way I have found to stop this is to continually tap the Ipad screen but there has to be a simpler method/ any help would be most welcome.
Welcome to the Apple Community.
Contact the developer of the Air Video app. -
I have a document made up of separate PDF files which reside in a folder and are linked to each other via hyperlinks. Each pdf file is set to open with bookmarks displayed, however if I link from one PDF file to another and use the "Previous View" button to navigate back to my starting point the bookmarks are replaced by "page thumbnails". Is there anyway to stop this from happening?
Hi Pusman,
While setting up the links, if you choose to open the file in a new window then you won't face this issue, then you can simply switch to the previous file and bookmark view will remain as it is.
Does that helps with your query?
Regards,
Rahul -
when importing files into fcpx from go pro hero2, some are importing as .mov and some as .mp4. when making a multi cam clip it will only add one type, if you try and add the other it says camera clip cannot be processed. need to figure out why it randomly imports differently, or how to add different file tyoes to multi cam.
here is one that is imported and stays .mp4. the specs are same as original file before import.
here is one that has changed somehow during import. specs on original file are same as above, but once it is imported it changes to this in event folder, and others randomly keep the above specs. -
I can't find out how to turn on and off the window above the iTunes list that includes the title of the song, name of artist, and time remaining to a song. It seems to appear rather randomly on my iMac.
You can download a complete iPad User Guide here: http://manuals.info.apple.com/en/ipad_user_guide.pdf
Also, Good Instructions http://www.tcgeeks.com/how-to-use-ipad-2/
Apple - iPad - Guided Tours
http://www.apple.com/ipad/videos/
Watch the videos see all the amazing iPad apps in action. Learn how to use FaceTime, Mail, Safari, Videos, Maps, iBooks, App Store, and more.
You can download this guide to your iPad.
iPad User Guide for iOS 5
http://itunes.apple.com/us/book/ipad-user-guide-for-ios-5/id470308101?mt=11
Cheers, Tom -
I ordered a book prom iphoto, and it was support to cost 610 NOK. but apple withdrew the amount 3 times from my acconu. how do I get the 1220 NOK back. who do I talk to or send e-mails to? I can't find any information. thanks!
Greetings,
Contact the Apple Online Store in your region (which I believe is Norway): http://store.apple.com/no/help/contact
or
http://support.apple.com/kb/HE57
Cheers. -
if i wanna make a new account and i have money on the one i have already can i have the amount i have on the one i got put on the new one i wanna make????
No
Why would you make a new account? -
I've had my iPod touch 5th gen for a little over 2 years now. a few weeks ago, I went to plug my iPod into the charger. After about 20 minutes I went to go get it so I could reply to texts and clear some notifications and I noticed that it was still at 20%. So I tried a different cord, different outlet, cleaned out any lint that might be in there, and reset the iPod more than once. Nothing worked. Eventually the problem corrected itself. But then it happened again a few days later. And then it happened just recently, and now it's happening again. In total it's happened 4 times, the first 3 times its corrected itself, but this time it's not. I'm not sure if there's anything else I can do, or if it's just a lost cause.
Not Charge
- See:
iPod touch: Hardware troubleshooting
iPhone and iPod touch: Charging the battery
If you can’t charge your iPhone, iPad, or iPod touch
- Try another cable unless the cable you tried works with another device
Iphone 5 lightning port charging problem - SOLUTION!
- Try another charging source
- Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
- Make an appointment at the Genius Bar of an Apple store.
Apple Retail Store - Genius Bar
Maybe you are looking for
-
Add new field infotype "z" in logical database selection screen pnp
Can add new field infotype "z" in logical database selection screen pnp I could explain how to realize Thanks
-
Payment popup (NEOS / Ogone ) does not appear in Safari 4.x
Dear people, We have noticed that the popups with the payment application on our website portal at portal.boip.int do not load anymore. Unfortunately, we can get no further information from Fortis Bank here in the Netherlands. They say it can be solv
-
PS Elements 10: Nach Farbe auswählen
Hallo, ich habe eine Grafik, in der sich Text und ein paar Strichzeichnungen befinden. Der Hintergrund ist ein Weißton. Ich möchte nun den weißen Hintergrund in Transparenz umwandeln. In Gimp geht das in wenigen Sekunden: mit der Pipette den Hintergr
-
Can I move my Photoshop CS4 to a different computer without messing up my Photoshop CC?
I just recently bought Photoshop CC. I'll be deleting my Photoshop CS4 off my computer soon. Is it possible to delete that off of my computer and instal it on a laptop? I read somewhere that I can deactivate my Photoshop CS4 and then install it on an
-
How to find insert,update on schema
Hi, I want to monitor insert,update or delete perform onparticular schema of the database . your early repsone is appriciated. Thanks in advance.