473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access particular character of a string without using pre defined functions?

57 New Member
I want to know how to access particular character of a String without using any pre defined functions(like charAt etc)? Since there are no pointers in java and the concept of character array being used as a String...So is there any way to do this?
Oct 7 '09 #1
10 4721
pbrockway2
151 Recognized Expert New Member
No. If you can't use any of the methods of the String (or other) class then you can't determine what any character is.

Then again without using some method or other, it's hard to see that you can do anything at all.
Oct 7 '09 #2
JosAH
11,448 Recognized Expert MVP
Strings are immutable so it won't let you fiddle with its internal data buffer at all, you have to use the methods it supplies for that purpose (such as charAt(...)). It doesn't supply any methods for changing that buffer at all, you can only read from the buffer.

kind regards,

Jos
Oct 8 '09 #3
myusernotyours
188 New Member
And why would you want to avoid the provided method? I thought that was the whole point of having the class.

Requirements never cease to amaze.

Regards,

Alex.
Oct 8 '09 #4
puneetsardana88
57 New Member
@myusernotyours
Will that become any good thing to ask?

Anyways thanks everyone for replying......S o how was charAt implemented ...I kw it must have used some other function for its task so on then how that function implemented?
Oct 8 '09 #5
myusernotyours
188 New Member
@puneetsardana88
Hey, don't get touchy. I meant well to ask that question since it sounds strange why any user of a class would want to avoid a provided method unless they have a very good reason to do that.

Wanting to know how a method is implemented is a totally different matter I think. Maybe I misunderstood what you wanted to do.

If you simply want to know how charAt is implemented, I believe the JDK install comes with the source code for the String class. Mostly you will find the methods that do not require native implementation. Additionally there is the OpenJDK (Open source java) project which will have the entire sources.

Regards,

Alex.
Oct 8 '09 #6
Frinavale
9,735 Recognized Expert Moderator Expert
Have you never implemented a String class before?
I think I must have implemented a String class a thousand times as school assignments or during exams or quizzes at school.

Anyways, think about what a String really is...it's just an array of chars.

The String class provides you with methods that add nice functionality which lets you interact with this underlying array of characters.

So the charAt() method will return you the character at the index in the array of characters that make up the String.
Oct 8 '09 #7
puneetsardana88
57 New Member
I too have implemented String class in c++ but with the aid of pointers there. In Java Character array is different from String......Act ually what I was thinking how these functions were implemented without existence of pointers.
Oct 8 '09 #8
myusernotyours
188 New Member
@puneetsardana88
A large part of Java is implemented in C. It's only that this is hidden from the programmer. Therefore there are no pointers in the Java Language, but there are there in the low level implementation of the classes.
The same can be said of the other languages on which *there are no pointers*.
These languages just makes the programmer's work easier not to have to deal with pointers directly.

Regards,

Alex.
Oct 8 '09 #9
pbrockway2
151 Recognized Expert New Member
There seem to be three questions so far:

How do I access characters in a String without using String (or other?) methods? - answer: you can't.

How do Java implementations provide String's functionality? - answer: read the code. (It seems to me that this is subtle and difficult as the Java language treats Strings somewhat specially and what you end up with is a complex solution to a complex problem involving efficiency and security).

How would I implement a string class?

The last is quite interesting. It might be as simple as wrapping a char array and providing the methods you want. Or it might be more meaningful. Why do you want a string class? What will it do? A string that's designed for efficient searches (of some particular type) might involve a more elaborate data structure than a simple array. A string that's going to participate in other data structures might have special (eg hashing) requirements. Should the string be mutable?
Oct 8 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
24031
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked tables in the database where the code resides. If we move the database with the data tables to a new directory, the links are no longer valid. I tried to update the links by changing the Connect property and refreshing: Set td = db.TableDefs(0)...
6
4748
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
13
6292
by: Chapman | last post by:
Some questions about strings: this is the extracted piece of my test code: /** **/ char *arry; arry = malloc(30*sizeof(arry)); arry = 'B'; arry = 'S'; arry = 'c';
7
96306
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %% should be used. Wouldn't it have been better (from design perspective) if the same escape character had been used in this case too. Forgive me for posting without verfying things with any standard compiler, i don't have the means for now.
5
2687
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all that's come before. To take an extreme example, suppose you have been writing Visual Basic applications for years now. If you're like many developers, you will have built up a substantial inventory of code in that time. And if you've been following...
8
11872
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
4
6404
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database to look a and I am loosing tremendious amounts of time trying to organize it so that I could view it. Regards, Alexandre Brisebois
32
8595
by: vonclausowitz | last post by:
Hi All, I have database with names on which I want to use the soundex option. So I have created two seperate fields for the Lastname and Firstname in which I save the Soundex version of a new name I save in the database. I have the soundex code with the 6 numeric option. So I save for example in the field LastnameSE = 600192 and in the FirstnameSE = 545910.
1
1561
by: string64 | last post by:
Hi to all.... anyone...how can you count the occurence of a particular character in a string without using any system-defined functions? tnx a lot!!!
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.