Get value from string in specific place
get character from string c++
find character position in string
char to string
how to get first two characters of a string in java
find character in string java
I'm using T-SQL language and I'm wondering the best way to get specific information from a string.
Example of string :
Category : azd Nom du fichier : 684157 Type de doc : info Id : 21542
The idea is to get the value "684157", which will be always between "fichier :" and "Type".
I have tried with
charindex but I miss something.
Here is my code
select substring(com, charindex('fichier : ', com)+len('fichier : '), charindex('Type', com)-charindex('fichier : ', com) + len('Type')) from myTable
There might be a neater way of doing this but here's a method using
SELECT SUBSTRING(com, CHARINDEX('fichier :', com) + LEN('fichier :'), -- start index CHARINDEX('Type :', com) - (CHARINDEX('fichier :', com) + LEN('fichier :'))) -- length FROM MyTable
startIndex is the index of
fichier : plus the length of
fichier :. The end index is the index of
Type :. For
SUBSTRING we need to use the start index and the length. To calculate the length of the substring we use the index of
Type : and subtract what we calculated for
Get value from string in specific place, There might be a neater way of doing this but here's a method using CHARINDEX and SUBSTRING . SELECT SUBSTRING(com For a fixed pattern, you can use two replace function to get your target string: Select col, replace (replace (col,'mydomain.com/Country/',''),'/Accounts/Users','')
This is what I would do:
SELECT LEFT(S.CutString,CHARINDEX(' Type :',S.CutString)) AS FinalString FROM (VALUES('Category : azd Nom du fichier : 684157 Type : info Id : 21542'))V(String) --Would be your table CROSS APPLY (VALUES(STUFF(V.String,1,CHARINDEX('fichier : ',V.String) + LEN('fichier : '),'')))S(CutString);
Manipulating Characters in a String (The Java™ Tutorials , You can get the character at a particular index within a string by invoking the charAt() that return the position within the string of a specific character or substring: Then substring uses the return value of lastIndexOf to extract the file name You call the GetValue (Object) overload to retrieve the value of a non-indexed property; if you try to retrieve the value of an indexed property, the method throws a TargetParameterCountException exception. You can determine whether a property is indexed or not by calling the GetIndexParameters method.
SELECT parsename(replace(replace(com,'fichier : ','.'), 'Type','.'),2) FROM MyTable
Add a Character to a String at a Given Position, Since the String class is final and immutable the function should return a new String with the added character. 2. Using a Character Array. To get the number at a specific place value you can use a formula based on the MOD function. By place value, we mean hundred thousands, ten thousands, thousands, hundreds, tens, ones, etc. In the example shown, the formula in cell D8 is: = MOD(B8, C8 * 10) - MOD(B8, C8)
C#, Note: This method always returns a new string which is modified with value inserted at the specified position. The return value type of Insert() method is System. \$\begingroup\$ @Dan Sure you can ;) The program I'm writing has to get log messages of a specific kind (employees quitting) from the Database and extract information about the 'request' that has been made regarding IT items (his equipment e.g.). Unfortunately, the log message format is more plain text than anything and I can't influence this
- Use charindex to find "fichier :" and "Type :" and then substring between the 2 of them
- Of course, the best way would be to not put yourself it this situation to begin with. Don't store data like that in your database. Either use well-known string formats such as json or xml, or simply store each data point in it's own column (which is the best option when it comes to relational databases).
- You are assuming that the input doesn't happen to contain any occurrences of ".". The OP's broad range of sample data doesn't make that clear.
- @HABO in such cases you just need to replace
.by not used char, e.g.
|, and after split replace back
- @HABO anyway variant provided by me is just an example how to achieve required result and can be useful in some cases