• 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Question about a string array

 
Ranch Hand
Posts: 225
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: 1402
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: 68928
275
  • 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: 7059
184
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: 11899
253
  • 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.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic