473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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 4692
pbrockway2
151 Expert 100+
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 Expert 8TB
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 100+
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
@myusernotyours
Will that become any good thing to ask?

Anyways thanks everyone for replying......So 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 100+
@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 Expert Mod 8TB
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
I too have implemented String class in c++ but with the aid of pointers there. In Java Character array is different from String......Actually what I was thinking how these functions were implemented without existence of pointers.
Oct 8 '09 #8
myusernotyours
188 100+
@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 Expert 100+
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
myusernotyours
188 100+
But what is really a string? What is the abstraction? It is in my opinion there is no more a best way than an array of characters. That's what the machine understands. If we want a more specialized cousin of the string, we do it another way. An example is the StringBuffer class in Java or the more specific StringBuilder.
But the common denominator is that every programmer will need the String class without all the bells and whistles. One that he can use *quick and dirty* without worrying about efficient searches, hashing and all. So it's okay to implement a specialized String, but that doesn't make your usual kind of String redundant.

Regards,

Alex.
Oct 8 '09 #11

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

Similar topics

3
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...
6
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...
13
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
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 %%...
5
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...
8
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
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...
32
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...
1
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.