How to split a string with a space in between?
Hi ABAP Guru's,
Can you please help me out? How can I split a string into two which has a space in between?
For example: lets suppose the string is 'LA CA USA'. How can I split this string? I have to dynamically determine the number of characters before the space therefore I cannot use number constant such as 2 or 3.
With best regards,
Ketan
Hi
Try like this
DATA : opbal TYPE p DECIMALS 2 VALUE 0.
SELECT * FROM zs_mkpf_mseg
into corresponding fields of table it_opbal
WHERE werks = itmat-werks
AND matnr = itmat-matnr
AND budat = s_budat-low.
* sort it_opbal by budat.
loop at it_opbal.
read table it_opbal.
IF it_opbal-shkzg = 'S'.
opbal = opbal + it_opbal-menge.
ELSEIF it_opbal-shkzg = 'H'.
opbal = opbal + it_opbal-menge * -1.
ENDIF.
endloop.
append opbal TO itab-opbal.
ENDFORM. " opbal_data
you can also use thi s
DATA: NAMES(30) TYPE C VALUE 'Charly, John , Peter',
NAMES2 TYPE STRING,
ONE(10) TYPE C,
TWO(10) TYPE C,
THREE TYPE STRING,
FOUR(4) TYPE C VALUE 'FOUR',
DELIMITER(2) VALUE ','.
SPLIT NAMES AT DELIMITER INTO ONE TWO.
* ONE contains 'Charly' and TWO contains 'John , Pet'.
* SY-SUBRC is 4, because TWO was not large enough to
* accommodate the whole of the remaining string
SPLIT NAMES AT ',' INTO ONE TWO THREE.
* ONE contains 'Charly', TWO contains ' John',
* THREE contains ' Peter'.
SPLIT NAMES AT ', ' INTO ONE THREE TWO.
* ONE contains 'Charly', THREE contains 'John',
* TWO contains 'Peter'.
CONCATENATE NAMES '' INTO NAMES2 SEPARATED BY SPACE.
SPLIT NAMES2 AT DELIMITER INTO ONE TWO THREE FOUR.
* ONE contains 'Charly', TWO contains 'John',
* THREE contains 'Peter ', FOUR is empty.
SPLIT NAMES2 AT DELIMITER INTO ONE FOUR THREE.
* ONE contains 'Charly', FOUR contains 'John',
* THREE contains 'Peter', SY-SUBRC is 4, since
* FOUR was not large enough (spaces are significant
* characters!)
Reward all helpfull answers
Regards
Pavan
Similar Messages
-
How to split a string with linefeed character ( LF ) as a delimiter in VB6?
Hi. I am writing a small program in VB 6.0.
I have a string named Data and it contains few characters along with <LF> in it. ( <LF> is a new line/line feed character).
I want to split this string with <LF> as delimiter and store the tokens in an array. I tried with split function and its giving me type mismatch error. Can anyone tell me how to do it?
I am giving the pseudo-code below.
Dim Data as string
Data = "hello, how are you<LS>good morning guys <LS> hi"
Dim strarray() as stringMsgbox(Data)
strarray = split(Data, "<LS>")
When i see the Data in message box before split function, it shows up in different lines like this:
hello, how are you
good morning guys
hi
I want the final array strarray to be like this: strarray(0) = "hello, how are you"
strarray(1) = "good morning guys "
strarray(2) = " hi"
The spaces can be as it is. Just i need the string to be delimited wherever <LS> is there.
Please help me as soon as possible. Though it is small one, i am stuck here.
Thanks in advance,
Satya.Hello,
This forum is for VB.NET, please check the following resources
http://www.vbforums.com/forumdisplay.php?1-Visual-Basic-6-and-Earlier
http://social.msdn.microsoft.com/Forums/vstudio/en-US/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b/where-to-post-your-vb-6-questions?forum=vbgeneral
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. -
How to split a string with regular expression
Hi.
I need to split a string with a regular expression.
Example
String = "this is; a test";rune haavik;12345;
And I want the output to be:
"this is; a test"
rune haavik
12345
If I use this code:
private void test1()
String str = "\"this is; a test\";rune haavik;12345;";
int i=0;
String[] tmp = str.split(";");
while(i<tmp.length)
System.out.println(tmp);
i++;
Then it splits also in the "" text.
Regards
Rune haavikRune haavik:
The most effective way to achieve the end result is, I believe, to read the characters one by one, using a flag that indicates if we are inside quotation or not.
Well, if we are in a mind game, then the following should do.
String[] tmp = str.split(";(?![^\"]*\";)"); -
How to split a string with a delimiting regular expression like "\r"
Hello!I am a fresh in java programming.Please don't deride my question.What I want to realize is to get the current caret lines and cols in a JTextPane. My question is :After I fetch the string content of the JTextPane and try to split it with the end-line token like "\r" or "\r\n",it always comes me an wrong position.
here is my code:
public void caretUpdate(CaretEvent e) {
int ln,col;
JTextPane textSource = (JTextPane)e.getSource();
String sourceString = textSource.getText();
String subString = sourceString.substring(0,
(e.getDot() == 0) ? 0 : e.getDot()-1);
String[] splitString = subString.split("\r",-1);
ln = splitString.length;
col = e.getDot() - subString.lastIndexOf("\r");
setCaretPosition(ln,col); //display ln and col in a label
I have got puzzled>_<.Please help me.Any help would be appreciated . (^-^)Swing text components always use "\n" to separate lines, not "\r" or "\r\n". When you read text in from a file or paste from the clipboard, the line separators are converted to "\n" if necessary. They save the info about what line separators were used in the source file, so if you write the text back to a file it converts them back.
-
How To Split the String for "."
Hi Friends
I am Using Following Code to Split one String.
String str = "Jeetendra.choudhary";
String[] sp_str = str.split(".");
wdComponentApi.getMessageManager.reportSuccess(str[0]);
wdComponentApi.getMessageManager.reportSuccess(str[1]);
but its throwing null pointer exception.
when i am using following code its working fine.
String str = "Jeetendra/choudhary";
String[] sp_str = str.split("/");
wdComponentApi.getMessageManager.reportSuccess(str[0]);
wdComponentApi.getMessageManager.reportSuccess(str[1]);
what may be the issue and how to split the string with "." ?
Thanks & Regards
Jeetendra"." is a special character.
Use
str.split("\\.");
Regards
Benjamin
Edited by: Benjamin Hansen on Dec 29, 2009 7:52 AM -
How to replace a character in a string with blank space.
Hi,
How to replace a character in a string with blank space.
Note:
I have to change string CL_DS_1===========CM01 to CL_DS_1 CM01.
i.e) I have to replace '=' with ' '.
I have already tried with <b>REPLACE ALL OCCURRENCES OF '=' IN temp_fill_string WITH ' '</b>
Its not working.Hi,
Try with this..
call method textedit- >replace_all
exporting
case_sensitive_mode = case_sensitive_mode
replace_string = replace_string
search_string = search_string
whole_word_mode = whole_word_mode
changing
counter = counter
exceptions
error_cntl_call_method = 1
invalid_parameter = 2.
<b>Parameters</b> <b> Description</b> <b> Possible values</b>
case_sensitive_mode Upper-/lowercase false Do not observe (default value)
true Observe
replace_string Text to replace the
occurrences of
SEARCH_STRING
search_string Text to be replaced
whole_word_mode Only replace whole words false Find whole words and
parts of words (default
value)
true Only find whole words
counter Return value specifying how
many times the search string
was replaced
Regards,
Jayaram... -
How to concatenate a string with spaces
Dear experts,
I would like to concatenate a string with three spaces, for example,
CONCATENATE 'X' SPACE SPACE SPACE 'Y' INTO LV_RESULT.
However, the result I got from executing the above statement is not 'X Y' as I want, but rather 'XY'.
I did try
CONCATENATE 'X' '***' 'Y' INTO LV_RESULT.
REPLACE '***' with ' ' INTO LV_RESULT.
still doesn't work.
How can I write ABAP code to archive such a result?
Any idea would be appreciated.
Vitthavat A.dear Oliver Hütköper and koolspy,
I tried your solutions, and it works.
so i awarded points to you.
anyway, while trying the 'respecting blanks', i got an error:
"".", "IN BYTE MODE", "SEPARATED BY ..." or "IN CHARACTER MODE" expected"
not sure what it means. but it's ok. the problem has been solved.
thanks again. -
How to concatenate a string with single quotes
Hi all,
how to concatenate a string with single quotes to a variable.
SathyaHi sathyabama,
1. simple
2. use TILDE character <b>(`)</b>
(just left to the '1' key)
<b> `'mystring'`</b>
3. just copy paste
report abc.
data : m(100) type c.
concatenate `'amit mittal'` 'hello' into m separated by space.
write m.
regards,
amit m. -
How to split the string by datetime in sql
Hi,
How to split the string by datetime in sql, I've a table with comments column stores comments by datetime, while selecting I want to split and show as in rows by each jobref.
can anyone help me in this please.
Thanks,declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated
output:
1) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910201'
2) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910201'
3) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910201'
4) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910202'
5) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910202'
6) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910202'
7) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910203'
8) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910203'
Thanks,
See this illustration
declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated','Vi2910203'
SELECT LEFT(p.u.value('.[1]','varchar(max)'),CHARINDEX(')',p.u.value('.[1]','varchar(max)'))-1) AS [Date],
'(' + p.u.value('.[1]','varchar(max)') AS comments,
lbiref
FROM
SELECT lbiref,CAST('<Root>' + STUFF(REPLACE(comments,'(','</Data><Data>'),1,7,'') + '</Data></Root>' AS XML) AS x
FROM @callcentre c
)t
CROSS APPLY x.nodes('/Root/Data')p(u)
and the output
Date comments lbiref
28/10/2014 14:56:14 (28/10/2014 14:56:14) xyz ..... call logged Vi2910201
28/10/2014 14:56:58 (28/10/2014 14:56:58) xyz ..... call updated Vi2910201
28/10/2014 14:57:41 (28/10/2014 14:57:41)xyz ..... call updated Vi2910201
29/10/2014 14:56:14 (29/10/2014 14:56:14) xyz ..... call logged Vi2910202
29/10/2014 14:56:58 (29/10/2014 14:56:58) xyz ..... call updated Vi2910202
29/10/2014 14:57:41 (29/10/2014 14:57:41)xyz ..... call updated Vi2910202
30/10/2014 14:56:14 (30/10/2014 14:56:14) xyz ..... call logged Vi2910203
30/10/2014 14:56:58 (30/10/2014 14:56:58) xyz ..... call updated Vi2910203
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to create a String with a specific size?
how to create a String with a specific size?
For example I want to create different Strings with the size of 100 , 1000 or 63k byte?String are immutable so just initialize it with the number of characters you want.
You might want to look at java.lang.StringBuffer and see if that's what you want. -
How to print a string with out using main method??
how to print a string with out using main method??
if we can tell me with example?
thanks in adavance
rajaHi,
actually there's none. The UITableView class needs to "know" the tableView's height so either it can calc <number of rows> times <row height> or it has to sum the height of each single row.
If the row which needs to be of different size always is the first or the last row you can user a tableHeader or tableFoot view.
Regards
Dirk -
how to split this string (char1)char2(char3)char4 into (char1)char2 , (char3)char4?
String[] result = "(char1)char2(char3)char4".split("\\(");I want :
result[0] = "(char1)char2" and
result[0] = "(char3)char4"
acutally char1,char2,char3, char4 ... is in the form of the below.
(any charactors except round brace)any charactors except round brace(any charactors except round brace)any charactors except round brace
I prefer String.split and Pattern.compile().split.
Edited by: iamjhkang on Feb 5, 2009 3:37 PM
Edited by: iamjhkang on Feb 5, 2009 3:41 PMiamjhkang wrote:
especially on
?= and ?<
Thanks.The following:
(?=...) // positive look ahead
(?!...) // negative look ahead
(?<=...) // positive look behind
(?<!...) // negative look behindare all "look-arounds". See: [http://www.regular-expressions.info/lookaround.html] -
How to pad a string with space or other character
length 14 string '00000000000155' turn to length 25 string '00000000000155 ' ,use space to pad string trail.
using following function:
CONCATENATE '00000000000155' ' ' into lv_string
but result is the lv_string ='00000000000155',the spaces were not added the string trail.
how to achieve this purpose padding string.
pls help me.
thank you.Hi ,
Not sure what exactly you require, But in my understanding you need to add one more spave after the doknr no. Please refer this code which could be more useful.
data: lv_objkt like aeoi-OBJKT,
lv_doknr like draw-doknr,
lv_dokar like draw-dokar,
lv_doktl like draw-doktl,
lv_dokvr like draw-dokvr,
lv_slen type i.
lv_dokar = 'DRW'.
lv_doknr = '00000000000155'.
lv_doktl = '000'.
lv_dokvr = '-'.
CONCATENATE lv_dokar lv_doknr INTO lv_objkt.
lv_slen = STRLEN( lv_objkt ).
lv_slen = lv_slen + 1.
lv_objkt+lv_slen(3) = lv_doktl.
CONCATENATE lv_objkt lv_dokvr INTO lv_objkt.
WRITE: lv_objkt. -
String with Trailing Space in a 4.7 / Basis 620 system
Hi
My customer is using SAP 4.7(Enterprise Management Version) / SAP BASIS Release 6.20 (Kernel 640).
We have a requirement to print a product label using a 2D Datamatrix barcode following HIBC standards. We are using a custom development object (Z function module) that builds the barcode string (variable length string) using a Mod43 calculated check digit as the last character of the string. One of the valid check digits is a "space" character as the last character of this barcode string.
Everything in our solution is working fine, except for the situation of the "space" check digit character at the end. We are running into an ABAP syntax limitation when we are trying to concatenate the calculated check digit onto the barcode string.
For example, we have a barcode value "+M53210250 " (within the quotes). This string ends with a SPACE character at the end. We are calculating the barcode value (some fixed elements + SAP material number, batch, etc.), then calculating the check digit, and concatenating the check digit onto the end of the initial barcode string value.
I have tried this in a higher version system and am able to make it work by using the statement CONCATENATE RESPECTING BLANKS. This syntax is not available with WebAS 620 however.
Here are the attempts we have made:
*Get HIBC 2D Barcode String
CONCATENATE E_HIBC_2D_BC L_CHECK_DIGIT INTO E_HIBC_2D_BC.
IF L_CHECK_DIGIT = SPACE.
The following attempts does not work
CONCATENATE with SPACE at end
Concatenate HIBC SPACE and a dummy variable like 'TEST' into HIBC builds a space in between the dummy and HIBC
and then when i split it the space is lost again.
Insert SPACE in the beginning bulding a new variable with 0(1) space followed by HIBC and then SHIFT CIRCULAR BY 1 place
It will work only if moved to a variable of length which is exactly HIBC + 1 char in length then by default the last char is SPACE.
Use a replacement variable which is not a HIBC Check Digit like # & ! ? ^ or other for SPACE
ECC 5.0 and HIGHER
*CONCATENATE {dobj1 dobj2 ...}|{LINES OF itab}
INTO result
[IN {BYTE|CHARACTER} MODE]
[SEPARATED BY sep]
[RESPECTING BLANKS].
*4.7 Version *
*CONCATENATE f1 ... fn INTO g.
*1. ... SEPARATED BY h
*2. ... IN BYTE MODE
*3. ... IN CHARACTER MODE
Having the customer upgrade to ECC 5.0 is not feasible to solve this.
If anyone has any alternative ideas on how to manage this variable length string and respect the trailing space, I would appreciate it.
I have searched the forums but the only solutions that are close deal with outputting to a file during a download or FTP, or else mention the newer syntax of CONCATENTATE with the option RESPECTING BLANKS, but that is not available in this release.If you could predict how long the string is (assuming you might determine whether the last element length is shorter than the db length), you could try to insert your check digit based upon fieldname+your_calculated_length(1) = checkdigit.
for example if batch is 3 cahr and you have '50' in the data, you could calculate as lv_len = strlen( the value ) .
lv_len = lv_len + 1.
move checkdigit to barcodefield+lv_len(1).
Perhaps something like this would allow you to work around. At any rate, if you can figure out if there's supposed to be one or ?? blanks on the end, specifying the position by +offset(columns) should do the trick, instead of the concatenate. -
How to Split the string using Substr and instr using loop condition
Hi every body,
I have below requirement.
I need to split the string and append with single quotes('') followed by , (comma) and reassign entire values into another variable. so that i can use it where clause of update statement
for example I am reciveing value as follows
ALN varchar2(2000):=(12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434);
Note: In the above variable i see 8 transactions, where as in real scenario i donot how many transaction i may recive.
after modification i need above transactions should in below format
ALTR Varchar2(2000):=('12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434');
kindly help how to use substr and instr in normal loop or for loop or while loop while modifying the above transactions.
Please help me to sort out this issue.
Many Thanks.
Edited by: user627525 on Dec 15, 2011 11:49 AMTry this - may not be the best way but...:
create or replace type myTableType as table of varchar2(255)
declare
v_array mytabletype;
v_new_str varchar2(4000);
function str2tbl
(p_str in varchar2,
p_delim in varchar2 default '.')
return myTableType
as
l_str long default p_str || p_delim;
l_n number;
l_data myTableType := myTabletype();
begin
loop
l_n := instr( l_str, p_delim );
exit when (nvl(l_n,0) = 0);
l_data.extend;
l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
l_str := substr( l_str, l_n+length(p_delim) );
end loop;
return l_data;
end;
begin
v_array := str2tbl ('12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434', ',');
FOR i IN 1 .. v_array.COUNT LOOP
v_new_str := v_new_str || ''''||v_array(i)||'''' || ',';
END LOOP;
dbms_output.put_line(RTRIM(v_new_str, ','));
end;
OUTPUT:
=======
'12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434'HTH
Edited by: user130038 on Dec 15, 2011 12:11 PM
Maybe you are looking for
-
BO XI 3.1 Enterprise SP4....Installation error messge
Hello Team, I am getting the following Error message while trying to install the Service pack 4 for XI 3.1 . Following are the error message"The install was unable to connect to the CMS. Please ensure the existing CMS hostname and port are correct, a
-
Change wording in Table of Contents
In the Table of Contents is it possible to change the text that says "Slide Title" to something else? Thanks.
-
Menu item moves in active state
I'm using the "Right Icon" to implement a long vertical seperator between menu items: laurensilverceramics.businesscatalyst.com I've deleted the Rollover, Mouse-Down and Active states of the menu items. But when a menu item becomes active - it move
-
New pe9 elements can not import pe6 catalog
I just purchased Photoshop Elements 9 and Premiere elements 9. I insstalled elements 9 to a win 7 system with no problem. I can not import my PE6 catalog to pe9. in the pe6 catalog manage the catalog is located in " catalog accessable by all users" I
-
Client Proxy: XML message not well-formed unexpected symbol 'target
Hi, I'm trying to get a client proxy to work based on several blogs (1387,1672) The error I'm getting now is: <SAP:ErrorHeader xmlns:SAP="http://sap.com/exchange/MessageFormat"> <SAP:Context /> <SAP:Code p1="XML message not well-formed in node (7