• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Question about a string array

 
Ranch Hand
Posts: 224
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: 1338
3
Netbeans IDE Spring Java
  • 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: 65113
247
  • 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.
 
Sheriff
Posts: 6128
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • 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: 10430
223
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!