473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trim in the middle

4
Hi there,I know that trim return a string withount spacing if spacing is at the begining,but I need that Countru Type be returned as CountryType....How can I do this
Nov 8 '06 #1
3 3267
vee10
141 100+
hi,

the following code can be written to solve that problem

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function loadfuc()
  3.     {
  4.    var strTemp = "country Type";
  5.   alert(strTemp);
  6.   debugger
  7.   var strTemp = Trim(strTemp);
  8.  
  9.   alert(strTemp);
  10.  
  11.     }
  12.  
  13.     function Trim(strTemp)
  14.     {
  15.     var string="",index1=0,index=0;
  16.     index=strTemp.indexOf(" ");
  17.     string=string+strTemp.substring(index1,index)+strTemp.substring(index+1,strTemp.length);;
  18.     return string;
  19.     }
  20.  
  21.  
  22.     </script>
  23.  
  24.  
  25.  





Hi there,I know that trim return a string withount spacing if spacing is at the begining,but I need that Countru Type be returned as CountryType....How can I do this
Nov 8 '06 #2
vee10
141 100+
hi

the above program only for one space like country Type but for an example country Type hai it doesnot work then check below code

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function loadfuc()
  3.     {
  4.    var strTemp = "country Type hai";
  5.   alert(strTemp);
  6.  
  7.   var strTemp = Trim(strTemp);
  8.  
  9.   alert(strTemp);
  10.  
  11.     }
  12.  
  13.     function Trim(strTemp)
  14.     {
  15.     var string="",index1=0,index=0;
  16.     index=strTemp.indexOf(" ");
  17.     while(index!=-1)
  18.     {
  19.     string=string+strTemp.substring(0,index);
  20.     strTemp=strTemp.substring(index+1,strTemp.length);
  21.     index=strTemp.indexOf(" ");
  22.        }
  23.  
  24.  
  25.     string=string+strTemp.substring(index+1,strTemp.length);
  26.  
  27.     return string;
  28.     }
  29.  
  30.  
  31.     </script>
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  





hi,

the following code can be written to solve that problem

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function loadfuc()
  3.     {
  4.    var strTemp = "country Type";
  5.   alert(strTemp);
  6.   debugger
  7.   var strTemp = Trim(strTemp);
  8.  
  9.   alert(strTemp);
  10.  
  11.     }
  12.  
  13.     function Trim(strTemp)
  14.     {
  15.     var string="",index1=0,index=0;
  16.     index=strTemp.indexOf(" ");
  17.     string=string+strTemp.substring(index1,index)+strTemp.substring(index+1,strTemp.length);;
  18.     return string;
  19.     }
  20.  
  21.  
  22.     </script>
  23.  
  24.  
  25.  
Nov 8 '06 #3
scripto
143 100+
Hi there,I know that trim return a string withount spacing if spacing is at the begining,but I need that Countru Type be returned as CountryType....How can I do this
this may be easier for you

Replace("Country Type", " ", "")
Nov 8 '06 #4

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

Similar topics

22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
9
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
3
by: Pascal | last post by:
bonjour hello I would like to trim a string of all its white spaces so i used myString.trim() but it doesn't work as supposed : unsecable space are remaining in the middle of my string... i...
2
by: rjoseph | last post by:
Hi guys I have a simple one for you. I am currently using the following script to display data from my database field onto my page ------------------------- <a...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft...
121
by: swengineer001 | last post by:
Just looking for a few eyes on this code other than my own. void TrimCString(char *str) { // Trim whitespace from beginning: size_t i = 0; size_t j; while(isspace(str)) {
8
by: Kevin Smith | last post by:
Hi, According to the intellisense help, string.Trim() "Removes all occurances or white space characters from the beginning and end of this instance." However, the follow code does not appear...
2
by: Peter Duniho | last post by:
On Wed, 08 Oct 2008 11:26:01 -0700, Kevin Smith <no@spam.comwrote: No, it wouldn't. Nor would it modify the String instance that s refers to. Strings are immutable. They are _never_...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.