How to delete Spaces in String
Can somebody help to modify my source, cos i want to delete certain space. Thanks
private static String printStar(int SpaceForStar){
String sDelOneSpace =" ", sAddOneSpace=" ", star ="*", sTtlSpace ="";
for(int i=0; i<numSpace; i++){
sTtlSpace += sAddOneSpace;
for(int i =0; i<8; i++){
sTtlSpace = sTtlSpace - sDelOneSpace; // seem that not working.. can somebody help Thanks
return sTtlSpace+star;
}Thanks in advance
jas
What you are trying to do will not work - subtraction of Strings does not make any sense.
To remove spaces, I suggest you use a StringTokenizer with space as dividing token. Lop trough the tokens and add them to a new String, like this:
public static void main (String[] args) throws Exception {
String withSpace = "aaa sss bbb";
System.out.println(removeSpaces(withSpace));
static String removeSpaces(String withSpaces) {
java.util.StringTokenizer t = new java.util.StringTokenizer(withSpaces, " ");
StringBuffer result = new StringBuffer("");
while (t.hasMoreTokens()) {
result.append(t.nextToken());
return result.toString();
}This will remove all spaces, and print "aaasssbbb". If you only want to remove the first or the last space, you can use indexOf() or lastIndexOff to find the space, and then substring to pick the text before and after that space and concatenate those two strings to a new string without the space:
static String removeFirstSpace(String withSpaces) {
int spaceIndex = withSpaces.indexOf(' '); //use lastIndexOf to remove last space
if (spaceIndex < 0) { //no spaces!
return withSpaces;
return withSpaces.substring(0, spaceIndex)
+ withSpaces.substring(spaceIndex+1, withSpaces.length());
}
Similar Messages
-
Help :how to remove spaces in string
could any body please help me in removing spaces from string suppose i have written vivek chhabra and i want to remove spaces in this string and want a string vivekchhabra then how this could be done
anybody help me please
vivekString string = "Hello - This is a test!";
String result = string.replaceAll(" ", "");
System.out.println(result);This code results the following output:
Hello-Thisisatest! -
How to delete spaces between each characters of a string in a file
In my program, I have a string, for example: str='abcdefg', when I print the string in command window, there is no space, everything is Ok But when I use the following method to write the string in a file(Mystring.txt):
File file= new File("C:\\MyString.txt");
fos = new FileOutputStream(file);
dos=new DataOutputStream(fos);
dos.writeChars(str);
when I open the file, between each character , there is a space, like "a b c d e f g", how to solve this problem? any idea or method?The spaces appear because you are using a DataOutputStream.
In fact, a DataOutputStream uses a specific way to encode primitive types. Moreover, data written through a DataOutputStream are supposed to be read back using a DataInputStream.
You should better use a FileWriter (or an OutputStreamWriter) instead. -
How to delete space in an internal table
Hi All,
In internal table I want to compress the leading space
After searching I found Condense and SHIFT LEFT DELETE leading space commands work it is written...
but when I write code A single space is appreaing in between the two fields...can any body help me where I am going wrong??
Ex:
data: begin of itab occurs 1 ,
PSAtext TYPE CHAR15,
psa type btrtl,
end of itab.
now o/p BEFORE CHANGE IS :
SBI-CT |1023
After condense is SBI-CT |1023
bETWEEN SBI-CT AND | there is a additional space. How can we avoid that?
Sas
Edited by: saslove sap on Sep 29, 2010 7:43 AMWell this is what I am going to solve this
data:begin of STRING OCCURS 1 ,
S1 TYPE STRING,
END OF STRING.
loop at itab.
concatenate itab-f1 itab-f2 into string-s1 seperated by '|'.
append string.
end of itab.
then I can transfer this string to Application server.
Thanks for all the contributions.
Regards
sas -
How to handle spaces in string?
Hi,
I am trying to filter out servers and certain OS from my powershell line below but I am getting an error. I think it is because of the Mac OS X line with spaces?:
The string is missing the terminator: '
$AllADClientObjects=@(Get-ADComputer -Filter "operatingSystem -notlike '*server*'" -and "operatingSystem -notlike '*"'Mac OS X'*'" -ErrorAction SilentlyContinue)Try this:
$AllADClientObjects = @(Get-ADComputer -Filter "operatingSystem -notlike '*server*' -and operatingSystem -notlike '*Mac OS X*'")
You shouldn't need the -ErrorAction SilentlyContinue when using filter because if it doesn't find anything, it will not throw an error like if you used -Identity.
Boe Prox
Blog |
Twitter
PoshWSUS |
PoshPAIG | PoshChat |
PoshEventUI
PowerShell Deep Dives Book -
How to trim spaces from string in BMM layer?
Hi friends,
I need to trim spaces from the string. can you please give me syntax with example.
ThanksHi
I have tried the below option , but it did not work . PS_D_PERSON
PERSON_ID is char type in the data base oracle , and it is defined as varchar on the physical layer .
So the table is loaded with space , i am not able to remove the space using trim both
Thanks
Sridhar.N -
Hi experts.
wa_char type char(255). This variable contains value 10 000.00( ie., 10<space>000.00).
how to move this value (10 000.00) into a variable of type currency of length 15.
Please help
i will award the points.Hi,
DATA: var1(255) TYPE c VALUE '10 000.00',
var2 type BPREI.
condense var1 no-gaps.
var2 = var1.
write : var2.
CONDENSE <field> NO-GAPS.
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb33e6358411d1829f0000e829fbfe/content.htm
Regards,
Srilatha. -
Delete spaces on the right of a string of characters
Hi,
I'd like to know how to delete space on the right of a string of characters and ONLY the ones on the right in order I can get the real length of the string (I don't want to condense the spaces between words even though there's more than one).
data: text(20).
text = 'SAP Forum'
In this case, if I use both DESCRIBE LENGTH and DESCRIBE OUTPUT LENGTH, the result will be 20, but the real length is 9.Use STRLEN( ), as described by the other posters.
To delete space chars on the right of a string, use following static method:
CALL METHOD cl_abap_string_utilities=>del_trailing_blanks
CHANGING
str = lv_text. -
Urgent: deleting a specific string form an existing .txt file
Plz help me with a sample code on how to delete a specific string form an existing .txt file..it is very urgent...
thanks in advanceString path = "D:\\text.txt";
File file = new File(path);
BufferedReader br = new BufferedReader(new FileReader(file));
String line = "";
String text = "";
while((line = br.readLine()) != null) {
text += line + "\n";
br.close();
String textToFind = "find";
int start = text.indexOf(textToFind);
if(start != -1) {
text = text.substring(0, start) + text.substring(start + textToFind.length());
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(text, 0, text.length());
bw.close();
} -
How to delete string or line from unix file(dataset) of application server
Hi All,
After transfer workarea information or all records into dataset(unix file). When I see the file in application server automatically the last line is shown a blank line. I am not passing any blank line.
I have tried for single record than also the file generates the last line(2nd line) also a blank line.
When I m reading the dataset, it is not reading the last blank line but why it is showing the last blank line?
How to delete string or line from unix file(dataset) of application server?
Please give your comments to resolve this.
Thanks
Tirumula Rao ChinniHi Rio,
I faced similar kind of issue working with files on UNIX platform.
The line is a line feed to remove it use
DATA : lv_carr_linefd TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf.
DATA : lv_carr_return TYPE char1,
lv_line_feed TYPE char1.
lv_line_feed = lv_carr_linefd(1).
lv_carr_return = lv_carr_linefd+1(1).
Note: IMP: The character in ' ' is not space but is a special
character set by pressing ALT and +255 simultaneosly
REPLACE ALL OCCURRENCES OF lv_line_feed IN l_string WITH ' '.
REPLACE ALL OCCURRENCES OF lv_carr_return IN l_string WITH ' '. -
How to delete the file with space in name
Hi
I want to delete the file "test ex.txt" file.
i run the following command in command prompt.i can delete the file successfully.
/bin/rm -f /mnt/"test ex.txt"
I want to run the command from java.So i am using the following code
String cmd = "/bin/rm -f /mnt/\"test ex.txt\"";
Runtime rt = Runtime.getRuntime();
process = rt.exec(cmd);
The file was not deleted.
How to delete the file with space in name?
Help meUse the form of exec that takes an array of command + args.
arr[0] = "/bin/rm"
arr[1] = "-f"
arr[2] = "/home/me/some directory with spaces";Or use ProcessBuilder, which is the preferred replacement for Runtime.exec, and which Runtime.exec calls. -
Does any one know , how to delete the others in itunes. it takes lot of space
does any one know , how to delete the others in itunes. it takes lot of space, i wanna delete that... Actually what it contains
Those are the data of the installed apps. Don't listen if someone says that it's an iOS, because it is not. On your iPhone, go to general > usage. It will show you all the programs installed on your iPhone. If you click any of them you will see how much of "others" it has (documents and data)
There's no way to delete it if you want to still have those apps. You can reinstal those which has the most "others" but after some time of usage, it will raise again. -
I have a 3g iPhone and I need to know how to delete old photos. Need to free up space and there is no clear way to delete these photos!! Can someone please let me know how to get rid of these pictures!!!! Help!!!
There are a number of ways to delete pictures from the Camera Roll. One is to open Camera Roll in the thumbnail view, tap the arrow button (top right), tap all the pictures you want to delete, tap the Delete button ant the bottom. Photo Library pictures are deleted by unchecking Sync Photos on the Photos tab of your iTunes sync settings, followed by syncing your phone.
-
How to sum space delimited hex values in a string, and do other stuff?
Hello
I am trying to write a Bourne shell script that takes a non-constant-length character string as input, converts each character to hexidecimal value, sums each value, takes the two's complement of the sum, logically ANDS it with FF, and if any of the resultant "nibbles" are a-f, print/save that nibble as A-F, for later display as a two-character-long character string
For example, assume a variable (as in non-constant) length variable $A
A="w04:0;2"
the road that I started down was to define
B=$( echo $A | od -An -t x1 -N"${#A}" )
# for this example, $B=77 30 34 3a 30 3b 32
It's the middle part where I need some magic. What I want to do is add the whitespace-delimited hex values of this string, for this example
C=77+30+34+3a+30+3b+32
so for this example, $C=1b2
then take two's complement of $C; for this example, $TWOS_COMP=ffff ffff ffff ffe4e
and logically AND it with FF; for this example, almost-final answer is 4e
then save final result as uppercase character string variable (for this example, variable's contents would be 4E)
Is what I'm trying to do intuitively obvious to any of you gurus out there, that could rattle off an answer? I'm okay with trashing my approach thus far and trying something totally different, within the constraint that it run inside a Bourne shell script.
Thanx in advance, if anybody can help!I've made progress. I've converted each character of a non-constant-length string $A into a space-delimited string of hex values, added them up, and retained the least significant byte (i.e., the 8 least significant bits). Here's how:
B=$( echo $A | od -An -t x1 -N"${#A}" )
D=0
for C in $B; do
C=0x$C
D=$(($D + $C))
done
D=$(($D & 16#FF))
D=`echo "ibase=10;obase=16;$D" | bc`
The missing piece now is how to take the two's complement of $D. Anybody out there with any ideas on how to handle the two's complement piece inside a Bourne shell?
Thanx -
My iPad says I cannot download any more because I am out of memory. I purchased space in cloud and still get same message. I do not know how to delete shows to open space. Can you help? Thanks.
Your iPad is physically out of storage space. Purchasing space in iCloud dosen't magically give your actual iPad more physical storage space.
You need to delete content off of your iPad.
https://discussions.apple.com/thread/5122738?start=0&tstart=0
http://m.youtube.com/watch?v=mZdBQoE37FA&desktop_uri=%2Fwatch%3Fv%3DmZdBQoE37FA
Maybe you are looking for
-
My ibook has been asking me to restart all day, and i cant seem to keep it on long enough to try and fis the problem as it just wants to shut down. This is the longest it has let me stay on, here is the error message panic(cpu 0 caller 0x000A8C00): U
-
LSMW - Idoc method - Urgent ??
Hi, What is "Allow structure assignment to EDIDC40" ? on the object attributes maintenance screen (step 1) in the LSMW Idoc inbound processing. we are using CRM 5.0 to test the BP creation with the help of IDOC methods. any inputs or step by step IDO
-
Install Windows XP on external USB drive - MSI 915P
I have a MSI 915P motherboard and i am trying to install Windows XP on my external USB hard drive. Everything is fine installing Windows XP but when it says to reboot the USB drive does not boot. Any help please?
-
Rman Script with ORacle10g in RHEL5
Dear Friends , I have to install ORacle10g in RHEL5 . Now I need to take rman backup and for this reason I make the following script : ============================ rman target / << ! run allocate channel t1 type disk; backup format 'df_%t_%s_%p' (dat
-
My Product Key Has Been Leaked
I had to do a Windows refresh and now my product key is invalid. I contacted Microsoft and they said it has been leaked and I need to contact HP. Before I called them I contacted HP and they said I needed to contact Microsoft. I am getting the runar