Results 1 to 7 of 7
  1. #1
    hotsauce1183 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Cast String to String

    Hi - I am working with a package that has implemented its own String Class. Consequently I am always finding that I need to convert from java.lang.String to soap.pkgname.String. The way I have been doing it so far is by looping manually through all the contents of the xxx.String using .split. But I am sure there must be an easier way using casting.

    Can someone please publish an example of how to cast java.lang.String to soap.pkgname.String and visa versa.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I strongly doubt you can cast one to the other. String can't be extended so their String class can't be a child class of String, so this makes no sense.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    You won't be able to cast as Fubarable clearly explained. Never seen the soap.pckgname.String class, but if it represents a String as the java.lang.String class then it should be easy to convert between the two by studying the API's.

  4. #4
    hotsauce1183 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks Guys. The API I was referring to was TripWire. Its only available as compiled code so its kind of hard for me to walk through it and in doing so I really dont learn any more than I can from the IDE prompts. And none of the methods listed have a name that implies casting or converting from one type to another. Guess I will just have to continue to do it with a manual loop:

    Java Code:
                 java.util.List<String> fListOfNodeFields;
                 fListOfNodeFields = getAllSvcFieldContents(sListOfNodeOrServiceFields,issue);      
                com.javahollic.tripwire.soap.tripwire.String tNodeList[] = new com.javahollic.tripwire.soap.tripwire.String[fListOfNodeFields.size()];
                String tName;
                int idx = 0;
                for (Iterator i = fListOfNodeFields.iterator(); i.hasNext();)
                {
                    tName = i.next().toString();
                    if ( !tName.equals("") )
                    {
                        tNodeList[idx++] = new com.javahollic.tripwire.soap.tripwire.String( tName );
                    }
                }
    Moderator Edit: Quote tags changed to Code tags
    Last edited by Fubarable; 02-02-2011 at 12:30 AM. Reason: Quote tags changed to Code tags

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Regardless of whether you have source code or not, have you had a chance to look at the tripwire API? As doWhile notes above, likely all your answers are to be found there. Also, you'll not want to use quote tags in your posts for code but instead should use code tags. I've made the changes in your post above.

  6. #6
    hotsauce1183 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Ah - thanks much Fubarable... I was looking for the label that left my code indented.

    I thought I had thoroughly looked at all of the API docs... I have been working on this project for quite a while and am fairly sure that I have copied all available material. I will certainly look again to see what I can find.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,970
    Rep Power
    19

    Default

    Who on earth thinks it's a good idea to create your own String class?

    "I've got this new class that holds characters."
    "What's should we call it?"
    "How about String?"
    "Yeah, what could possibly go wrong with that name?"

Similar Threads

  1. Replies: 6
    Last Post: 05-27-2009, 01:17 AM
  2. Cast From Image to String
    By Deepa in forum New To Java
    Replies: 4
    Last Post: 03-03-2009, 02:07 PM
  3. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 10:43 AM
  4. How to cast an Object into a specific type (Integer/String) at runtime
    By mailtogagan@gmail.com in forum Advanced Java
    Replies: 2
    Last Post: 12-03-2007, 01:04 PM
  5. Replies: 1
    Last Post: 08-02-2007, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •