• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Question about a string array  RSS feed

 
Ranch Hand
Posts: 215
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose there is a String array called "myStringArray" and it is passed to a method called "myTestMethod".

Suppose this String array has the following values:
myStringArray[0] = "Arial;Arial;Greetings";
myStringArray[1] = "<strong>My name is John Doe</strong>";

I would like to set the String array called "text" equal to the values of the String array "myStringArray", but I don't want the String array "text" to have the font names and the xml tags.
In other words, I would like "text" to have these values:
text[0] = "Greetings";
text[1] = "My name is John Doe";

How can I do this? Below is the code I have written so far.

 
Ranch Hand
Posts: 1329
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is maybe using the  Method substring() an option you would like to consider?
 
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The substring() method might work, but you will have to work out the indices to split on. You will have to look for semicolons, angle signs, etc. The whole thing looks error‑prone to me. You would have similar problems with String#split(), even if you already know how to write the appropriate regular expressions.
 
Marshal
Posts: 5993
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several XML processors in Java that can help (google java xml processing).  If you just want the XML tags to go away, a regex like <[^>]*> will probably work, as in:
 
Saloon Keeper
Posts: 10248
216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:XML [...] regex


These two words in the same sentence should always cause a knee-jerk reaction that is strong enough to topple the desk you're sitting at.

NEVER combine XML and regular expressions. You simply can not process XML well with regular expressions because XML is not a regular language, but another type of context-free language. For every regular expression that you write to process XML in a certain way, I can write a piece of XML for which it will fail.

Your first suggestion was the right way to go: Use an XML processor to process XML.
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!