473,545 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to escape special characters through JAVA

14 New Member
For eg:

Expand|Select|Wrap|Line Numbers
  1.  public String DisplayinURLFormat(String sampleString,int urlIndex)
  2.     {
  3.           String tempString = "";
  4.              int beginIndex = sampleString.indexOf("http", urlIndex); 
  5.              if(beginIndex!=-1)
  6.              {
  7.                  int endIndex = sampleString.indexOf(' ', beginIndex);
  8.                  if(endIndex==-1)
  9.                  {
  10.                      endIndex = sampleString.length();
  11.                  }
  12.                  String hyperString = sampleString.substring(beginIndex,endIndex);
  13.                  tempString = sampleString.substring(0, beginIndex)+"<a href='" + hyperString + "'>"+hyperString+"</a>" + sampleString.substring( endIndex,sampleString.length());
  14.                  urlIndex = endIndex + hyperString.length() + 13;
  15.                  sampleString= tempString;
  16.                  return DisplayinURLFormat(sampleString,urlIndex);  
  17.              }
  18.              else
  19.                  return sampleString;
  20.     }
  21.  
Here i am making a string to URl if the string containd any http format.

like if i enter sampleStruing as "go to http://www.google.com" the http string shud appear in URl. but for this i need to use the escapeXml flag in HTML to ignore the conversion of < and > characters. Is there any other way to make the escaped in JAV code itself
Jul 19 '07 #1
8 15329
prometheuzz
197 Recognized Expert New Member
...

like if i enter sampleStruing as "go to http://www.google.com" the http string shud appear in URl. but for this i need to use the escapeXml flag in HTML to ignore the conversion of < and > characters. Is there any other way to make the escaped in JAV code itself
Err, I'm no XML/web man myself, so I don't know exactly what this kind of escape thing is you're talking about.
However, could you perhaps give a couple of example input-Strings and desired output-String? Perhaps then I can give you a hand.
Jul 19 '07 #2
ikilldeath
14 New Member
OK, I have a string sampleString which contains a substring which is supposed to be printed in URL format, for that i have written the above function.

But anyhow i needed to use the escapeXml flag to set it to false in the jsp page not to convert the <a ref> tag to &lt;a ref &gt;.
The problem doing this is it may escape some of the valid tags which i dint want to escape. Here i want only <a ref></a> tags to be escaped
Jul 19 '07 #3
prometheuzz
197 Recognized Expert New Member
OK, I have a string sampleString which contains a substring which is supposed to be printed in URL format, for that i have written the above function.

But anyhow i needed to use the escapeXml flag to set it to false in the jsp page not to convert the <a ref> tag to &lt;a ref &gt;.
The problem doing this is it may escape some of the valid tags which i dint want to escape. Here i want only <a ref></a> tags to be escaped
Could you provide examples of in- and output?
For example: String "aaaaaaaabbbbbb bbbbbbbbsssssss sssssssssssbbbb " comes in, and "aaaaaaaabbbXXX XXXXbbsssssXXXX Xssssssssbbb" should come out.
Jul 19 '07 #4
ikilldeath
14 New Member
"go to <a href='http://www.google.com' ></a>" is input

"go to &lt;a href='http://www.google.com' &gt; &lt;/a&gt;" is the out put
Jul 19 '07 #5
ikilldeath
14 New Member
but the output should be

"go to http://www.google.com "
Jul 19 '07 #6
prometheuzz
197 Recognized Expert New Member
but the output should be

"go to http://www.google.com "
Output to what? Are we talking about Java here?
Jul 19 '07 #7
prometheuzz
197 Recognized Expert New Member
"go to <a href='http://www.google.com' ></a>" is input

"go to &lt;a href='http://www.google.com' &gt; &lt;/a&gt;" is the out put
Look at String's replaceAll(...) method.
Jul 19 '07 #8
JosAH
11,448 Recognized Expert MVP
Look at String's replaceAll(...) method.
Yeah, regexps! Gimme an 'r'! gimme an 'e'! gimme a 'g'! gimme an 'e'! ... erm,
sorry; it won't happen again.

kind regards,

Jos ;-)
Jul 19 '07 #9

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

Similar topics

3
17186
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in oracle database. When i retrieve the data, some of the special characters have been changed to ??? and also
4
5247
by: Ewok | last post by:
let me just say. it's not by choice but im dealing with a .net web app (top down approach with VB and a MySQL database) sigh..... Anyhow, I've just about got all the kinks worked out but I am having trouble preserving data as it gets entered into the database. Primarily, quotes and special characters. Spcifically, I noticed it stripped...
17
30639
by: Carl Mercier | last post by:
Hi, Is it possible to use special characters like \n or \t in a VB.NET string, just like in C#? My guess is NO, but maybe there's something I don't know. If it's not possible, does anybody know of a VB.NET function (somebody must have coded this already) that will interpret strings containings those special characters, and handle them...
8
3648
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special...
0
1505
by: SeanGerman | last post by:
Howdy, Is there a way to explicitly escape special characters (particularly & (&amp;) and ' (&apos;)) when writing a data set with the WriteXml method? I know this is supposed to happen automatically (according to MS), but in my case, it doesn't. I'm pulling data from MS-SQL with c#, filling data tables with SqlDataAdapter and a query,...
5
3663
by: Doc | last post by:
Hello! I'm experiencing a little problem counting the number of characters in a textarea on a html page. This is the content type of my HTML document content="text/html; charset=iso-8859-1" I have a textarea that I want to limit to 400 characters, but the enduser can enter special characters (like €, v, 8, ...). I have
25
5301
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found out that addslashes() can be used escape some characters, but I'm having some more problems with for instance ä, å and µ (since the text is...
3
22270
by: forest demon | last post by:
i need to escape characters, such as ( % and/or _ and/or [ ), since i have database entries that have such characters in them. the following piece works fine in an SQL statement (c#), but doesn't return entries that have one of the above characters in the argument. ... like '%" + tbProduct.Text.Replace("'", "''") + "%' ... ...
3
10180
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class. This is not a regular expression tutorial. Assumes you are already familiar with basic regular expression concepts and terminology. If not, you may want...
0
7387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7798
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7738
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5956
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1862
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
688
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.