Replacing chars in string - windows

I have this code:
inspect w-string1 replacing all x'C48D' by 'c'
But I got this error by compiler
Operand has wrong size
Is there any solution how to replace more chars by one char thru inspect command. Or I must do it by myself via perform loop?

When using the INSPECT statement, both strings must be the same length. The only way to replace multiple characters by a different number of characters is to write your own loop to do it.

Related

Symbol # in variable cannot be handled

I got a CSV file from my front-end as a XString and after I convert it into String it looks as follows:
In the next step I'm trying to perform SPLIT lv_string AT '##' INTO TABLE itab so I can get my data but it doesn't split anything, itab contains one line equal to lv_string.
If I try REPLACE '#' IN lv_string WITH space, lv_string doesn't change and sy-subrc is 4.
From my point of view I have this problem because the symbol # is used by SAP in this context as a symbol for non-printable symbols (that result from the conversion byte->string).
My question is: how may I use SPLIT/REPLACE with # in this case?
I also thought that I can change the SAP code page when converting XString to String but I already use the SAP code page 4110 (utf-8) and don't know a better alternative...
When you display a variable with the debugger, it displays the generic character # (U+0023) for all control characters which are not assigned a glyph ("non-printable symbols" as you say).
If the variable corresponds to the contents of a text file, and ## frequently occurs, there is a big chance that it's the combination of the control characters U+000D and U+000A which correspond to "newline" in Windows files.
In the backend debugger, you can check the hexadecimal values of those characters by clicking the button "Hexadezimal" (shown in your screenshot).
You may use the variable CL_ABAP_CHAR_UTILITIES=>CR_LF which contains those two control characters.

Julia: Strange characters in my string

I scraped some text from the internet, which I put in an UTF8String. I can use this string normally, but when I select some specific characters (strange character with accents, like in my case รบ), which are not part of the UTF8 standard, I get an error, saying that I used invalid indexes. This only happens when the string contains strange characters; my code works with normal string that do not contain strange characters.
Any way to solve this?
EDIT:
I have a variable word of type SubString{UTF8String}
When I use do method(word), no problems occur. When I do method(word[2:end]) (assuming length of at least 2), I get an error in case the second character is strange (not in UTF8).
Julia does indexing on byte positions instead of character position. It is way more efficient for a variable length encoding like UTF-8, but it makes some operations use some more boilerplate.
The problem is that some codepoints is encoded as multiple bytes and when you slice the string from 2:end you would have got half of the first character (witch is invalid and you get an error).
The solution is to get the second valid index instead of 2 in the slice. I think that is something like str[nextind(str, 1):end]
PS. Sorry for a less than clear answer on my phone.
EDIT:
I tried this, and it seems like SubString{UTF8String} and UTF8String has different behaviour on slicing. I've reported it as bug #7811 on GitHub.

sscanf skips capital 'N' letter

I have got a strange sscanf problem with a capital letter 'N'(maybe I do not understand something correct me please):
Example 1:
char cBuff[128];
sscanf("GUIDNameNENE","%*[GUIDName]%127s" ,cBuff);
returns cBuff:ENE
Example 2:
char cBuff[128];
sscanf("GUIDNamenENE","%*[GUIDName]%127s" ,cBuff);
returns cBuff:nENE
Example 3:
char cBuff[128];
sscanf("GUIDNaMENE","%*[GUIDNa]%127s" ,cBuff);
returns cBuff:ENE
I have tried many other variants but still always skips capital N.
Where is the problem?
Thank you in advance!
%[GUIDName] is not a weird way of quoting and matching an exact string. It defines a set of characters that will match. They will match in any order, and they will match repeatedly.
The longest match for the set %[GUIDName] in your input is GUIDNameN.
You could of course say %*[G]%*[U]%*[I]%*[D]%*[N]%*[a]%*[m]%*[e] and that would not eat any of the characters GUIDNam, but it would still eat multiple es.
I would guess the reason it skips the capital N is because it's part of the set of characters that you ignore. The key point is that what you specify between the brackets are a set of characters to match, not in a fixed order, but rather that sscanf tries to match the longest string consisting of only the characters after the '[' up to the first matching ']'. If I recall correct.
You could try specifying the size for the set of characters to be skipped like this:
sscanf("GUIDNameNENE","%*8[GUIDName]%127s" ,cBuff);
But that will of course only work if the string always is eight characters long and if it is you could choose to just ignore the eight initial characters like this:
sscanf("GUIDNameNENE","%*8s%127s" ,cBuff);

Delete all spaces at the beginning of each line in a variable that contains a large string

I use a vbs variable that contains a large string. This string holds on many lines and some of these lines begin with one or more spaces. I need to delete all spaces at beginning of each line in my variable. To do that, I use a regular expression such as ^\s+, but it only ignores spaces at begin of string and not in all lines as part of my variable.
Please could you please, help me with something that do it?
Thank you in advance
The variable holds a string that contains line break characters, is that? if it is, try setting the property Multiline of the RegExp to true.
From: http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/
(You could also split each line into an array and do the Regex on a loop on each)

Ruby execute shell command and get array

I'm getting a string of few lines from the shell. Is it possible to get an Array with each line being its element?
Sure, depending on the output you could just split it. For example:
lines = `ls`.split
This solution is independent of the method you're using to execute the program. As long as you get the complete string you can split it.
The original question was splitting on lines, and the split function, by default, splits on white space. While that may be sufficient, you may want to pass in a regular expression, as in:
`ls -l`.split(/$/)
Which returns each line in a separate element in the array. However, it doesn't get rid of the initial carriage return or line feed. For that, you will want to use the map function to iterate over the array and apply strip to each, as in:
`ls -l`.split(/$/).map(&:strip)

Resources