Search Results

Search found 35326 results on 1414 pages for 'string similarity'.

Page 7/1414 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Problem with Replacing special characters in a string

    - by Hossein
    Hi, I am trying to feed some text to a special pupose parser. The problem with this parser is that it is sensitive to ()[] characters and in my sentence in the text have quite a lot of these characters. The manual for the parser suggests that all the ()[] get replaced with \( \) \[ \]. So using str.replace i am using to attach \ to all of those charcaters. I use the code below: a = 'abcdef(1234)' a.replace('(','\(') however i get this as my output: 'abcdef\\(1234)' What is wrong with my code? can anyone provide me a solution to solve this for these characters?

    Read the article

  • Replacing substring in a string

    - by user177785
    I am uploading a image file to the server. Now after uploading the file to the server I need to rename the file with an id, but the extension of the file should be retained. Eg: if I upload the file image1.png then my server script should retain the extension .png. But I need to change the substring to some other substring (primary key of db). image1.png should be renamed to 123.png image2.jpg should be renamed to somevalue.jpg The image can be of any extension like .png, .jpg, .jpeg etc. I want to rename then in such a way that the image/file extension should be retained.

    Read the article

  • String to array or Array to string tips on formats, etc

    - by user316841
    hi, first of all thanks for taking your time! I'm a junior Dev, working with PHP + mysql. My issue: I'm saving data from a form to my database. From this form, there's only need to save the contacts: Name, phone number, address. But, it would be nice to have a small reference to the user answers. Let's say for each question we've got a value betwee 1 and 4. Since there's no need to create a table just for it, because what's needed is just the personal contacts. I'm thinking of recording each question/answer, as a letter and its correspondent value. Example (A2, B1, C5, D3, etc). My question is: Is there a format I could afterwards, handle easily ? Convert to array (string to array) in case the client change ideas, and ask this data, placed in table columns ? Just to prevent this situation! Example, From (A2, B1, C5 ) to array( "A" = "1", "B" = "1", "C" = "5" ) For now I guess, Regex is the answer, but it's allways hard to figure it out and I'm allways getting in troubles =) Thanks!

    Read the article

  • SQL SERVER – Find First Non-Numeric Character from String

    - by pinaldave
    It is fun when you have to deal with simple problems and there are no out of the box solution. I am sure there are many cases when we needed the first non-numeric character from the string but there is no function available to identify that right away. Here is the quick script I wrote down using PATINDEX. The function PATINDEX exists for quite a long time in SQL Server but I hardly see it being used. Well, at least I use it and I am comfortable using it. Here is a simple script which I use when I have to identify first non-numeric character. -- How to find first non numberic character USE tempdb GO CREATE TABLE MyTable (ID INT, Col1 VARCHAR(100)) GO INSERT INTO MyTable (ID, Col1) SELECT 1, '1one' UNION ALL SELECT 2, '11eleven' UNION ALL SELECT 3, '2two' UNION ALL SELECT 4, '22twentytwo' UNION ALL SELECT 5, '111oneeleven' GO -- Use of PATINDEX SELECT PATINDEX('%[^0-9]%',Col1) 'Position of NonNumeric Character', SUBSTRING(Col1,PATINDEX('%[^0-9]%',Col1),1) 'NonNumeric Character', Col1 'Original Character' FROM MyTable GO DROP TABLE MyTable GO Here is the resultset: Where do I use in the real world – well there are lots of examples. In one of the future blog posts I will cover that as well. Meanwhile, do you have any better way to achieve the same. Do share it here. I will write a follow up blog post with due credit to you. Reference : Pinal Dave (http://blog.SQLAuthority.com) Filed under: PostADay, SQL, SQL Authority, SQL Function, SQL Query, SQL Server, SQL String, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • String.valueOf(int value) gives error [closed]

    - by Davidrd91
    I am trying to convert an int into a String so that I can put the String values into an SQLite Cursor. I've tried multiple syntax and methods but none seem to work for me. The Error occurs in MangaItemDB() while trying to convert any Int types aswell as the boolean. I've looked through several articles like this one but none works for me. Here's my code: public class MangaItem { private int _id; private String mangaName; private String mangaLink; private static String mangaAlpha; private static int mangaCount; private static int alphaCount; private boolean mangaComplete = false; public MangaItem MangaItemDB(int id, String mangaName, String mangaLink, String mangaAlpha, String mangaCount, String alphaCount, String mangaComplete) { MangaItem MangaItemDB = new MangaItem(); MangaItemDB._id = id; MangaItemDB.mangaName = mangaName; MangaItemDB.mangaLink = mangaLink; MangaItemDB.mangaAlpha = mangaAlpha; MangaItemDB.mangaCount = String.valueOf(int mangaCount); MangaItemDB.alphaCount = Integer.toString(getAlphaCount()); MangaItemDB.mangaComplete = String.valueOf(getMangaComplete()); return MangaItemDB; } public void incrementMangaCount() { mangaCount++; } public int getMangaCount() { return mangaCount; } public void incrementAlphaCount() { alphaCount++; } public int getAlphaCount() { return alphaCount; } public boolean setMangaComplete(boolean mangaComplete) { return true; } public boolean getMangaComplete() { return mangaComplete; } /** * @return the mangaName */ public String getMangaName() { return mangaName; } /** * @param mangaName the mangaName to set */ public void setMangaName(String mangaName) { this.mangaName = mangaName; } /** * @return the mangaLink */ public String getMangaLink() { return mangaLink; } /** * @param mangaLink the mangaLink to set */ public void setMangaLink(String mangaLink) { this.mangaLink = mangaLink; } /** * @return the mangaAlpha */ public String getMangaAlpha() { return mangaAlpha; } /** * @param mangaAlpha the mangaAlpha to set */ public void setMangaAlpha(String mangaAlpha) { this.mangaAlpha = mangaAlpha; } /** * @return the _id */ public int get_id() { return _id; } /** * @param _id the _id to set */ public void set_id(int _id) { this._id = _id; } } The lines : MangaItemDB.mangaCount = String.valueOf(mangaCount); MangaItemDB.alphaCount = Integer.toString(getAlphaCount()); MangaItemDB.mangaComplete = String.valueOf(getMangaComplete()); all give "Type mismatch: cannot convert from String to Int"

    Read the article

  • String Length Evaluating Incorrectly

    - by Justin R.
    My coworker and I are debugging an issue in a WCF service he's working on where a string's length isn't being evaluated correctly. He is running this method to unit test a method in his WCF service: // Unit test method public void RemoveAppGroupTest() { string addGroup = "TestGroup"; string status = string.Empty; string message = string.Empty; appActiveDirectoryServicesClient.RemoveAppGroup("AOD", addGroup, ref status, ref message); } // Inside the WCF service [OperationBehavior(Impersonation = ImpersonationOption.Required)] public void RemoveAppGroup(string AppName, string GroupName, ref string Status, ref string Message) { string accessOnDemandDomain = "MyDomain"; RemoveAppGroupFromDomain(AppName, accessOnDemandDomain, GroupName, ref Status, ref Message); } public AppActiveDirectoryDomain(string AppName, string DomainName) { if (string.IsNullOrEmpty(AppName)) { throw new ArgumentNullException("AppName", "You must specify an application name"); } } We tried to step into the .NET source code to see what value string.IsNullOrEmpty was receiving, but the IDE printed this message when we attempted to evaluate the variable: 'Cannot obtain value of local or argument 'value' as it is not available at this instruction pointer, possibly because it has been optimized away.' (None of the projects involved have optimizations enabled). So, we decided to try explicitly setting the value of the variable inside the method itself, immediately before the length check -- but that didn't help. // Lets try this again. public AppActiveDirectoryDomain(string AppName, string DomainName) { // Explicitly set the value for testing purposes. AppName = "AOD"; if (AppName == null) { throw new ArgumentNullException("AppName", "You must specify an application name"); } if (AppName.Length == 0) { // This exception gets thrown, even though it obviously isn't a zero length string. throw new ArgumentNullException("AppName", "You must specify an application name"); } } We're really pulling our hair out on this one. Has anyone else experienced behavior like this? Any tips on debugging it?

    Read the article

  • Document Similarity: Comparing two documents efficiently

    - by seanieb
    I have a loop that calculates the similarity between two documents. It collects all the tokens in a document and their scores, and places them in dictionary. It then compares the dictionaries This is what I have so far, it works, but is super slow: # Doc A cursor1.execute("SELECT token, tfidf_norm FROM index WHERE doc_id = %s", (docid[i][0])) doca = cursor1.fetchall() #convert tuple to a dictionary doca_dic = dict((row[0], row[1]) for row in doca) #Doc B cursor2.execute("SELECT token, tfidf_norm FROM index WHERE doc_id = %s", (docid[j][0])) docb = cursor2.fetchall() #convert tuple to a dictionary docb_dic = dict((row[0], row[1]) for row in docb) # loop through each token in doca and see if one matches in docb for x in doca_dic: if docb_dic.has_key(x): #calculate the similarity by summing the products of the tf-idf_norm similarity += doca_dic[x] * docb_dic[x] print "similarity" print similarity I'm pretty new to Python, hence this mess. I need to speed it up, any help would be appreciated. Thanks.

    Read the article

  • PHP mySQL - replace some string inside string

    - by apis17
    i want to replace ALL comma , into ,<space> in all address table in my mysql table. For example, +----------------+----------------+ | Name | Address | +----------------+----------------+ | Someone name | A1,Street Name | +----------------+----------------+ Into +----------------+----------------+ | Name | Address | +----------------+----------------+ | Someone name | A1, Street Name| +----------------+----------------+ Thanks in advance.

    Read the article

  • Interning strings in Java

    - by Tiny
    The following segment of code interns a string. String str1="my"; String str2="string"; String concat1=str1+str2; concat1.intern(); System.out.println(concat1=="mystring"); The expression concat1=="mystring" returns true because concat1 has been interned. If the given string mystring is changed to string as shown in the following snippet. String str11="str"; String str12="ing"; String concat11=str11+str12; concat11.intern(); System.out.println(concat11=="string"); The comparison expression concat11=="string" returns false. The string held by concat11 doesn't seem to be interned. What am I overlooking here? I have tested on Java 7, update 11.

    Read the article

  • Add string to another string

    - by daemonfire300
    Hi there, I currently encountered a problem: I want to handle adding strings to other strings very efficiently, so I looked up many methods and techniques, and I figured the "fastest" method. But I quite can not understand how it actually works: def method6(): return ''.join([`num` for num in xrange(loop_count)]) From source (Method 6) Especially the ([numfor num in xrange(loop_count)]) confused me totally.

    Read the article

  • Python/Django Concatenate a string depending on whether that string exists

    - by Douglas Meehan
    I'm creating a property on a Django model called "address". I want address to consist of the concatenation of a number of fields I have on my model. The problem is that not all instances of this model will have values for all of these fields. So, I want to concatenate only those fields that have values. What is the best/most Pythonic way to do this? Here are the relevant fields from the model: house = models.IntegerField('House Number', null=True, blank=True) suf = models.CharField('House Number Suffix', max_length=1, null=True, blank=True) unit = models.CharField('Address Unit', max_length=7, null=True, blank=True) stex = models.IntegerField('Address Extention', null=True, blank=True) stdir = models.CharField('Street Direction', max_length=254, null=True, blank=True) stnam = models.CharField('Street Name', max_length=30, null=True, blank=True) stdes = models.CharField('Street Designation', max_length=3, null=True, blank=True) stdessuf = models.CharField('Street Designation Suffix',max_length=1, null=True, blank=True) I could just do something like this: def _get_address(self): return "%s %s %s %s %s %s %s %s" % (self.house, self.suf, self.unit, self.stex, self.stdir, self.stname, self.stdes, self.stdessuf) but then there would be extra blank spaces in the result. I could do a series of if statements and concatenate within each, but that seems ugly. What's the best way to handle this situation? Thanks.

    Read the article

  • collect string in loop and printout all the string outside loop

    - by user1508163
    I'm newbie here and there is some question that I want have some lesson from you guys. For example: #include <stdio.h> #include<stdlib.h> #include<ctype.h> void main() { char name[51],selection; do { printf("Enter name: "); fflush(stdin); gets(name); printf("Enter another name?(Y/N)"); scanf("%c",&selection); selection=toupper(selection); }while (selection=='Y'); //I want to printout the entered name here but dunno the coding printf("END\n"); system("pause"); } As I know when the loops perform will overwrite the variable then how I perform a coding that will printout all the name user entered? I have already ask my tutor and he is ask me to use pointer, can anyone guide me in this case?

    Read the article

  • Why use string.Empty over "" when assigning to a string object

    - by dreza
    I've been running StyleCop over my code and one of the recommendations SA1122 is to use string.Empty rather than "" when assigning an empty string to a value. My question is why is this considered best practice. Or, is this considered best practice? I assume there is no compiler difference between the two statements so I can only think that it's a readability thing? UPDATE: Thanks for the answers but it's been kindly pointed out this question has been asked many times already on SO, which in hind-sight I should have considered and searched first before asking here. Some of these especially forward links makes for interesting reading. SO question and answer Jon Skeet answer to question

    Read the article

  • What's a good way of building up a String given specific start and end locations?

    - by Michael Campbell
    (java 1.5) I have a need to build up a String, in pieces. I'm given a set of (sub)strings, each with a start and end point of where they belong in the final string. Was wondering if there were some canonical way of doing this. This isn't homework, and I can use any licensable OSS, such as jakarta commons-lang StringUtils etc. My company has a solution using a CharBuffer, and I'm content to leave it as is (and add some unit tests, of which there are none (?!)) but the code is fairly hideous and I would like something easier to read. As I said this isn't homework, and I don't need a complete solution, just some pointers to libraries or java classes that might give me some insight. The String.Format didn't seem QUITE right... I would have to honor inputs too long and too short, etc. Substrings would be overlaid in the order they appear (in case of overlap). As an example of input, I might have something like: String:start:end FO:0:3 (string shorter than field) BAR:4:5 (String larger than field) BLEH:5:9 (String overlays previous field) I'd want to end up with FO BBLEH 01234567890

    Read the article

  • What's a good way of building up a String where you specific start and end locations?

    - by Michael Campbell
    (java 1.5) I have a need to build up a String, in pieces. I'm given a set of (sub)strings, each with a start and end point of where they belong in the final string. Was wondering if there were some canonical way of doing this. This isn't homework, and I can use any licensable OSS, such as jakarta commons-lang StringUtils etc. My company has a solution using a CharBuffer, and I'm content to leave it as is (and add some unit tests, of which there are none (?!)) but the code is fairly hideous and I would like something easier to read. As I said this isn't homework, and I don't need a complete solution, just some pointers to libraries or java classes that might give me some insight. The String.Format didn't seem QUITE right... I would have to honor inputs too long and too short, etc. Substrings would be overlaid in the order they appear (in case of overlap). As an example of input, I might have something like: String:start:end FO:0:3 (string shorter than field) BAR:4:5 (String larger than field) BLEH:5:9 (String overlays previous field) I'd want to end up with FO BBLEH 01234567890

    Read the article

  • NameValueCollection vs Dictionary<string,string>

    - by frankadelic
    Any reason I should use Dictionary<string,string instead of NameValueCollection? (in C# / .NET Framework) Option 1, using NameValueCollection: //enter values: NameValueCollection nvc = new NameValueCollection() { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; // retrieve values: foreach(string key in nvc.AllKeys) { string value = nvc[key]; // do something } Option 2, using Dictionary<string,string... //enter values: Dictionary<string, string> dict = new Dictionary<string, string>() { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; // retrieve values: foreach (KeyValuePair<string, string> kvp in dict) { string key = kvp.Key; string val = kvp.Value; // do something } For these use cases, is there any advantage to use one versus the other? Any difference in performance, memory use, sort order, etc.?

    Read the article

  • How to have a function with a nullable string parameter in Go?

    - by yuku
    I'm used to Java's String where we can pass null rather than "" for special meanings, such as use a default value. In Go, string is a primitive type, so I cannot pass nil (null) to a parameter that requires a string. I could write the function using pointer type, like this: func f(s *string) so caller can call that function either as f(nil) or // not so elegant temp := "hello"; f(&temp) but the following is unfortunately not allowed: // elegant but disallowed f(&"hello"); What is the best way to have a parameter that receives either a string or nil?

    Read the article

  • Detecting similar words among n text documents

    - by javanes
    Hi; I have n documents and want to find common words that are included in these documents. For example I want to say (n-3) documents include the word "web". Certainly I can do this by basic data structures but there maybe efficient algorithm or a way to handle same words with different suffix. Is there any algorithm for such purposes? I am unfamiliar with datamining world. In general manner is there a term used for efforts of finding similarities between different documents? If there is then I will make my research easily. Thanks.

    Read the article

  • handle null values for string when implementing IXmlSerializable interface

    - by user208081
    I have the following class that implements IXmlSerializable. When implementing WriteXml(), I need to handle the case where the string members of this class may be null values. What is the best way of handling this? Currently, I am using the default constructor in which all the string properties are initialized to empty string values. This way, when WriteXml() is called, the string will not be null. One other way I could do this is check using String.IsNullOrEmpty before writing each string in xml. Any suggestions on how I can improve this code? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; using System.Globalization; namespace TCS.Common.InformationObjects { public sealed class FaxSender : IXmlSerializable { #region Public Constants private const string DEFAULT_CLASS_NAME = "FaxSender"; #endregion Public Constants #region Public Properties public string Name { get; set; } public string Organization { get; set; } public string PhoneNumber { get; set; } public string FaxNumber { get; set; } public string EmailAddress { get; set; } #endregion Public Properties #region Public Methods #region Constructors public FaxSender() { Name = String.Empty; Organization = String.Empty; PhoneNumber = String.Empty; FaxNumber = String.Empty; EmailAddress = String.Empty; } public FaxSender(string name, string organization, string phoneNumber, string faxNumber, string emailAddress) { Name = name; Organization = organization; PhoneNumber = phoneNumber; FaxNumber = faxNumber; EmailAddress = emailAddress; } #endregion Constructors #region IXmlSerializable Members public System.Xml.Schema.XmlSchema GetSchema() { throw new NotImplementedException(); } public void ReadXml(System.Xml.XmlReader reader) { throw new NotImplementedException(); } public void WriteXml(System.Xml.XmlWriter xmlWriter) { try { // <sender> xmlWriter.WriteStartElement("sender"); // Write the name of the sender as an element. xmlWriter.WriteElementString("name", this.Name.ToString(CultureInfo.CurrentCulture)); // Write the organization of the sender as an element. xmlWriter.WriteElementString("organization", this.Organization.ToString(CultureInfo.CurrentCulture)); // Write the phone number of the sender as an element. xmlWriter.WriteElementString("phone_number", this.PhoneNumber.ToString(CultureInfo.CurrentCulture)); // Write the fax number of the sender as an element. xmlWriter.WriteElementString("fax_number", this.FaxNumber.ToString(CultureInfo.CurrentCulture)); // Write the email address of the sender as an element. xmlWriter.WriteElementString("email_address", this.EmailAddress.ToString(CultureInfo.CurrentCulture)); // </sender> xmlWriter.WriteEndElement(); } catch { // Rethrow any exceptions. throw; } } #endregion IXmlSerializable Members #endregion Public Methods } }

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >